vrshoot

annotate libs/assimp/IFCUtil.cpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40
nuclear@0 41 /** @file IFCUtil.cpp
nuclear@0 42 * @brief Implementation of conversion routines for some common Ifc helper entities.
nuclear@0 43 */
nuclear@0 44
nuclear@0 45 #include "AssimpPCH.h"
nuclear@0 46
nuclear@0 47 #ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
nuclear@0 48
nuclear@0 49 #include "IFCUtil.h"
nuclear@0 50 #include "PolyTools.h"
nuclear@0 51 #include "ProcessHelper.h"
nuclear@0 52
nuclear@0 53 namespace Assimp {
nuclear@0 54 namespace IFC {
nuclear@0 55
nuclear@0 56 // ------------------------------------------------------------------------------------------------
nuclear@0 57 void TempOpening::Transform(const IfcMatrix4& mat)
nuclear@0 58 {
nuclear@0 59 if(profileMesh) {
nuclear@0 60 profileMesh->Transform(mat);
nuclear@0 61 }
nuclear@0 62 if(profileMesh2D) {
nuclear@0 63 profileMesh2D->Transform(mat);
nuclear@0 64 }
nuclear@0 65 extrusionDir *= IfcMatrix3(mat);
nuclear@0 66 }
nuclear@0 67
nuclear@0 68 // ------------------------------------------------------------------------------------------------
nuclear@0 69 aiMesh* TempMesh::ToMesh()
nuclear@0 70 {
nuclear@0 71 ai_assert(verts.size() == std::accumulate(vertcnt.begin(),vertcnt.end(),size_t(0)));
nuclear@0 72
nuclear@0 73 if (verts.empty()) {
nuclear@0 74 return NULL;
nuclear@0 75 }
nuclear@0 76
nuclear@0 77 std::auto_ptr<aiMesh> mesh(new aiMesh());
nuclear@0 78
nuclear@0 79 // copy vertices
nuclear@0 80 mesh->mNumVertices = static_cast<unsigned int>(verts.size());
nuclear@0 81 mesh->mVertices = new aiVector3D[mesh->mNumVertices];
nuclear@0 82 std::copy(verts.begin(),verts.end(),mesh->mVertices);
nuclear@0 83
nuclear@0 84 // and build up faces
nuclear@0 85 mesh->mNumFaces = static_cast<unsigned int>(vertcnt.size());
nuclear@0 86 mesh->mFaces = new aiFace[mesh->mNumFaces];
nuclear@0 87
nuclear@0 88 for(unsigned int i = 0,n=0, acc = 0; i < mesh->mNumFaces; ++n) {
nuclear@0 89 aiFace& f = mesh->mFaces[i];
nuclear@0 90 if (!vertcnt[n]) {
nuclear@0 91 --mesh->mNumFaces;
nuclear@0 92 continue;
nuclear@0 93 }
nuclear@0 94
nuclear@0 95 f.mNumIndices = vertcnt[n];
nuclear@0 96 f.mIndices = new unsigned int[f.mNumIndices];
nuclear@0 97 for(unsigned int a = 0; a < f.mNumIndices; ++a) {
nuclear@0 98 f.mIndices[a] = acc++;
nuclear@0 99 }
nuclear@0 100
nuclear@0 101 ++i;
nuclear@0 102 }
nuclear@0 103
nuclear@0 104 return mesh.release();
nuclear@0 105 }
nuclear@0 106
nuclear@0 107 // ------------------------------------------------------------------------------------------------
nuclear@0 108 void TempMesh::Clear()
nuclear@0 109 {
nuclear@0 110 verts.clear();
nuclear@0 111 vertcnt.clear();
nuclear@0 112 }
nuclear@0 113
nuclear@0 114 // ------------------------------------------------------------------------------------------------
nuclear@0 115 void TempMesh::Transform(const IfcMatrix4& mat)
nuclear@0 116 {
nuclear@0 117 BOOST_FOREACH(IfcVector3& v, verts) {
nuclear@0 118 v *= mat;
nuclear@0 119 }
nuclear@0 120 }
nuclear@0 121
nuclear@0 122 // ------------------------------------------------------------------------------
nuclear@0 123 IfcVector3 TempMesh::Center() const
nuclear@0 124 {
nuclear@0 125 return std::accumulate(verts.begin(),verts.end(),IfcVector3()) / static_cast<IfcFloat>(verts.size());
nuclear@0 126 }
nuclear@0 127
nuclear@0 128 // ------------------------------------------------------------------------------------------------
nuclear@0 129 void TempMesh::Append(const TempMesh& other)
nuclear@0 130 {
nuclear@0 131 verts.insert(verts.end(),other.verts.begin(),other.verts.end());
nuclear@0 132 vertcnt.insert(vertcnt.end(),other.vertcnt.begin(),other.vertcnt.end());
nuclear@0 133 }
nuclear@0 134
nuclear@0 135 // ------------------------------------------------------------------------------------------------
nuclear@0 136 void TempMesh::RemoveDegenerates()
nuclear@0 137 {
nuclear@0 138 // The strategy is simple: walk the mesh and compute normals using
nuclear@0 139 // Newell's algorithm. The length of the normals gives the area
nuclear@0 140 // of the polygons, which is close to zero for lines.
nuclear@0 141
nuclear@0 142 std::vector<IfcVector3> normals;
nuclear@0 143 ComputePolygonNormals(normals, false);
nuclear@0 144
nuclear@0 145 bool drop = false;
nuclear@0 146 size_t inor = 0;
nuclear@0 147
nuclear@0 148 std::vector<IfcVector3>::iterator vit = verts.begin();
nuclear@0 149 for (std::vector<unsigned int>::iterator it = vertcnt.begin(); it != vertcnt.end(); ++inor) {
nuclear@0 150 const unsigned int pcount = *it;
nuclear@0 151
nuclear@0 152 if (normals[inor].SquareLength() < 1e-5f) {
nuclear@0 153 it = vertcnt.erase(it);
nuclear@0 154 vit = verts.erase(vit, vit + pcount);
nuclear@0 155
nuclear@0 156 drop = true;
nuclear@0 157 continue;
nuclear@0 158 }
nuclear@0 159
nuclear@0 160 vit += pcount;
nuclear@0 161 ++it;
nuclear@0 162 }
nuclear@0 163
nuclear@0 164 if(drop) {
nuclear@0 165 IFCImporter::LogDebug("removing degenerate faces");
nuclear@0 166 }
nuclear@0 167 }
nuclear@0 168
nuclear@0 169 // ------------------------------------------------------------------------------------------------
nuclear@0 170 void TempMesh::ComputePolygonNormals(std::vector<IfcVector3>& normals,
nuclear@0 171 bool normalize,
nuclear@0 172 size_t ofs) const
nuclear@0 173 {
nuclear@0 174 size_t max_vcount = 0;
nuclear@0 175 std::vector<unsigned int>::const_iterator begin = vertcnt.begin()+ofs, end = vertcnt.end(), iit;
nuclear@0 176 for(iit = begin; iit != end; ++iit) {
nuclear@0 177 max_vcount = std::max(max_vcount,static_cast<size_t>(*iit));
nuclear@0 178 }
nuclear@0 179
nuclear@0 180 std::vector<IfcFloat> temp((max_vcount+2)*4);
nuclear@0 181 normals.reserve( normals.size() + vertcnt.size()-ofs );
nuclear@0 182
nuclear@0 183 // `NewellNormal()` currently has a relatively strange interface and need to
nuclear@0 184 // re-structure things a bit to meet them.
nuclear@0 185 size_t vidx = std::accumulate(vertcnt.begin(),begin,0);
nuclear@0 186 for(iit = begin; iit != end; vidx += *iit++) {
nuclear@0 187 if (!*iit) {
nuclear@0 188 normals.push_back(IfcVector3());
nuclear@0 189 continue;
nuclear@0 190 }
nuclear@0 191 for(size_t vofs = 0, cnt = 0; vofs < *iit; ++vofs) {
nuclear@0 192 const IfcVector3& v = verts[vidx+vofs];
nuclear@0 193 temp[cnt++] = v.x;
nuclear@0 194 temp[cnt++] = v.y;
nuclear@0 195 temp[cnt++] = v.z;
nuclear@0 196 #ifdef _DEBUG
nuclear@0 197 temp[cnt] = std::numeric_limits<IfcFloat>::quiet_NaN();
nuclear@0 198 #endif
nuclear@0 199 ++cnt;
nuclear@0 200 }
nuclear@0 201
nuclear@0 202 normals.push_back(IfcVector3());
nuclear@0 203 NewellNormal<4,4,4>(normals.back(),*iit,&temp[0],&temp[1],&temp[2]);
nuclear@0 204 }
nuclear@0 205
nuclear@0 206 if(normalize) {
nuclear@0 207 BOOST_FOREACH(IfcVector3& n, normals) {
nuclear@0 208 n.Normalize();
nuclear@0 209 }
nuclear@0 210 }
nuclear@0 211 }
nuclear@0 212
nuclear@0 213 // ------------------------------------------------------------------------------------------------
nuclear@0 214 // Compute the normal of the last polygon in the given mesh
nuclear@0 215 IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const
nuclear@0 216 {
nuclear@0 217 size_t total = vertcnt.back(), vidx = verts.size() - total;
nuclear@0 218 std::vector<IfcFloat> temp((total+2)*3);
nuclear@0 219 for(size_t vofs = 0, cnt = 0; vofs < total; ++vofs) {
nuclear@0 220 const IfcVector3& v = verts[vidx+vofs];
nuclear@0 221 temp[cnt++] = v.x;
nuclear@0 222 temp[cnt++] = v.y;
nuclear@0 223 temp[cnt++] = v.z;
nuclear@0 224 }
nuclear@0 225 IfcVector3 nor;
nuclear@0 226 NewellNormal<3,3,3>(nor,total,&temp[0],&temp[1],&temp[2]);
nuclear@0 227 return normalize ? nor.Normalize() : nor;
nuclear@0 228 }
nuclear@0 229
nuclear@0 230 // ------------------------------------------------------------------------------------------------
nuclear@0 231 void TempMesh::FixupFaceOrientation()
nuclear@0 232 {
nuclear@0 233 const IfcVector3 vavg = Center();
nuclear@0 234
nuclear@0 235 std::vector<IfcVector3> normals;
nuclear@0 236 ComputePolygonNormals(normals);
nuclear@0 237
nuclear@0 238 size_t c = 0, ofs = 0;
nuclear@0 239 BOOST_FOREACH(unsigned int cnt, vertcnt) {
nuclear@0 240 if (cnt>2){
nuclear@0 241 const IfcVector3& thisvert = verts[c];
nuclear@0 242 if (normals[ofs]*(thisvert-vavg) < 0) {
nuclear@0 243 std::reverse(verts.begin()+c,verts.begin()+cnt+c);
nuclear@0 244 }
nuclear@0 245 }
nuclear@0 246 c += cnt;
nuclear@0 247 ++ofs;
nuclear@0 248 }
nuclear@0 249 }
nuclear@0 250
nuclear@0 251 // ------------------------------------------------------------------------------------------------
nuclear@0 252 void TempMesh::RemoveAdjacentDuplicates()
nuclear@0 253 {
nuclear@0 254
nuclear@0 255 bool drop = false;
nuclear@0 256 std::vector<IfcVector3>::iterator base = verts.begin();
nuclear@0 257 BOOST_FOREACH(unsigned int& cnt, vertcnt) {
nuclear@0 258 if (cnt < 2){
nuclear@0 259 base += cnt;
nuclear@0 260 continue;
nuclear@0 261 }
nuclear@0 262
nuclear@0 263 IfcVector3 vmin,vmax;
nuclear@0 264 ArrayBounds(&*base, cnt ,vmin,vmax);
nuclear@0 265
nuclear@0 266
nuclear@0 267 const IfcFloat epsilon = (vmax-vmin).SquareLength() / static_cast<IfcFloat>(1e9);
nuclear@0 268 //const IfcFloat dotepsilon = 1e-9;
nuclear@0 269
nuclear@0 270 //// look for vertices that lie directly on the line between their predecessor and their
nuclear@0 271 //// successor and replace them with either of them.
nuclear@0 272
nuclear@0 273 //for(size_t i = 0; i < cnt; ++i) {
nuclear@0 274 // IfcVector3& v1 = *(base+i), &v0 = *(base+(i?i-1:cnt-1)), &v2 = *(base+(i+1)%cnt);
nuclear@0 275 // const IfcVector3& d0 = (v1-v0), &d1 = (v2-v1);
nuclear@0 276 // const IfcFloat l0 = d0.SquareLength(), l1 = d1.SquareLength();
nuclear@0 277 // if (!l0 || !l1) {
nuclear@0 278 // continue;
nuclear@0 279 // }
nuclear@0 280
nuclear@0 281 // const IfcFloat d = (d0/sqrt(l0))*(d1/sqrt(l1));
nuclear@0 282
nuclear@0 283 // if ( d >= 1.f-dotepsilon ) {
nuclear@0 284 // v1 = v0;
nuclear@0 285 // }
nuclear@0 286 // else if ( d < -1.f+dotepsilon ) {
nuclear@0 287 // v2 = v1;
nuclear@0 288 // continue;
nuclear@0 289 // }
nuclear@0 290 //}
nuclear@0 291
nuclear@0 292 // drop any identical, adjacent vertices. this pass will collect the dropouts
nuclear@0 293 // of the previous pass as a side-effect.
nuclear@0 294 FuzzyVectorCompare fz(epsilon);
nuclear@0 295 std::vector<IfcVector3>::iterator end = base+cnt, e = std::unique( base, end, fz );
nuclear@0 296 if (e != end) {
nuclear@0 297 cnt -= static_cast<unsigned int>(std::distance(e, end));
nuclear@0 298 verts.erase(e,end);
nuclear@0 299 drop = true;
nuclear@0 300 }
nuclear@0 301
nuclear@0 302 // check front and back vertices for this polygon
nuclear@0 303 if (cnt > 1 && fz(*base,*(base+cnt-1))) {
nuclear@0 304 verts.erase(base+ --cnt);
nuclear@0 305 drop = true;
nuclear@0 306 }
nuclear@0 307
nuclear@0 308 // removing adjacent duplicates shouldn't erase everything :-)
nuclear@0 309 ai_assert(cnt>0);
nuclear@0 310 base += cnt;
nuclear@0 311 }
nuclear@0 312 if(drop) {
nuclear@0 313 IFCImporter::LogDebug("removing duplicate vertices");
nuclear@0 314 }
nuclear@0 315 }
nuclear@0 316
nuclear@0 317 // ------------------------------------------------------------------------------------------------
nuclear@0 318 void TempMesh::Swap(TempMesh& other)
nuclear@0 319 {
nuclear@0 320 vertcnt.swap(other.vertcnt);
nuclear@0 321 verts.swap(other.verts);
nuclear@0 322 }
nuclear@0 323
nuclear@0 324 // ------------------------------------------------------------------------------------------------
nuclear@0 325 bool IsTrue(const EXPRESS::BOOLEAN& in)
nuclear@0 326 {
nuclear@0 327 return (std::string)in == "TRUE" || (std::string)in == "T";
nuclear@0 328 }
nuclear@0 329
nuclear@0 330 // ------------------------------------------------------------------------------------------------
nuclear@0 331 IfcFloat ConvertSIPrefix(const std::string& prefix)
nuclear@0 332 {
nuclear@0 333 if (prefix == "EXA") {
nuclear@0 334 return 1e18f;
nuclear@0 335 }
nuclear@0 336 else if (prefix == "PETA") {
nuclear@0 337 return 1e15f;
nuclear@0 338 }
nuclear@0 339 else if (prefix == "TERA") {
nuclear@0 340 return 1e12f;
nuclear@0 341 }
nuclear@0 342 else if (prefix == "GIGA") {
nuclear@0 343 return 1e9f;
nuclear@0 344 }
nuclear@0 345 else if (prefix == "MEGA") {
nuclear@0 346 return 1e6f;
nuclear@0 347 }
nuclear@0 348 else if (prefix == "KILO") {
nuclear@0 349 return 1e3f;
nuclear@0 350 }
nuclear@0 351 else if (prefix == "HECTO") {
nuclear@0 352 return 1e2f;
nuclear@0 353 }
nuclear@0 354 else if (prefix == "DECA") {
nuclear@0 355 return 1e-0f;
nuclear@0 356 }
nuclear@0 357 else if (prefix == "DECI") {
nuclear@0 358 return 1e-1f;
nuclear@0 359 }
nuclear@0 360 else if (prefix == "CENTI") {
nuclear@0 361 return 1e-2f;
nuclear@0 362 }
nuclear@0 363 else if (prefix == "MILLI") {
nuclear@0 364 return 1e-3f;
nuclear@0 365 }
nuclear@0 366 else if (prefix == "MICRO") {
nuclear@0 367 return 1e-6f;
nuclear@0 368 }
nuclear@0 369 else if (prefix == "NANO") {
nuclear@0 370 return 1e-9f;
nuclear@0 371 }
nuclear@0 372 else if (prefix == "PICO") {
nuclear@0 373 return 1e-12f;
nuclear@0 374 }
nuclear@0 375 else if (prefix == "FEMTO") {
nuclear@0 376 return 1e-15f;
nuclear@0 377 }
nuclear@0 378 else if (prefix == "ATTO") {
nuclear@0 379 return 1e-18f;
nuclear@0 380 }
nuclear@0 381 else {
nuclear@0 382 IFCImporter::LogError("Unrecognized SI prefix: " + prefix);
nuclear@0 383 return 1;
nuclear@0 384 }
nuclear@0 385 }
nuclear@0 386
nuclear@0 387 // ------------------------------------------------------------------------------------------------
nuclear@0 388 void ConvertColor(aiColor4D& out, const IfcColourRgb& in)
nuclear@0 389 {
nuclear@0 390 out.r = static_cast<float>( in.Red );
nuclear@0 391 out.g = static_cast<float>( in.Green );
nuclear@0 392 out.b = static_cast<float>( in.Blue );
nuclear@0 393 out.a = static_cast<float>( 1.f );
nuclear@0 394 }
nuclear@0 395
nuclear@0 396 // ------------------------------------------------------------------------------------------------
nuclear@0 397 void ConvertColor(aiColor4D& out, const IfcColourOrFactor& in,ConversionData& conv,const aiColor4D* base)
nuclear@0 398 {
nuclear@0 399 if (const EXPRESS::REAL* const r = in.ToPtr<EXPRESS::REAL>()) {
nuclear@0 400 out.r = out.g = out.b = static_cast<float>(*r);
nuclear@0 401 if(base) {
nuclear@0 402 out.r *= static_cast<float>( base->r );
nuclear@0 403 out.g *= static_cast<float>( base->g );
nuclear@0 404 out.b *= static_cast<float>( base->b );
nuclear@0 405 out.a = static_cast<float>( base->a );
nuclear@0 406 }
nuclear@0 407 else out.a = 1.0;
nuclear@0 408 }
nuclear@0 409 else if (const IfcColourRgb* const rgb = in.ResolveSelectPtr<IfcColourRgb>(conv.db)) {
nuclear@0 410 ConvertColor(out,*rgb);
nuclear@0 411 }
nuclear@0 412 else {
nuclear@0 413 IFCImporter::LogWarn("skipping unknown IfcColourOrFactor entity");
nuclear@0 414 }
nuclear@0 415 }
nuclear@0 416
nuclear@0 417 // ------------------------------------------------------------------------------------------------
nuclear@0 418 void ConvertCartesianPoint(IfcVector3& out, const IfcCartesianPoint& in)
nuclear@0 419 {
nuclear@0 420 out = IfcVector3();
nuclear@0 421 for(size_t i = 0; i < in.Coordinates.size(); ++i) {
nuclear@0 422 out[i] = in.Coordinates[i];
nuclear@0 423 }
nuclear@0 424 }
nuclear@0 425
nuclear@0 426 // ------------------------------------------------------------------------------------------------
nuclear@0 427 void ConvertVector(IfcVector3& out, const IfcVector& in)
nuclear@0 428 {
nuclear@0 429 ConvertDirection(out,in.Orientation);
nuclear@0 430 out *= in.Magnitude;
nuclear@0 431 }
nuclear@0 432
nuclear@0 433 // ------------------------------------------------------------------------------------------------
nuclear@0 434 void ConvertDirection(IfcVector3& out, const IfcDirection& in)
nuclear@0 435 {
nuclear@0 436 out = IfcVector3();
nuclear@0 437 for(size_t i = 0; i < in.DirectionRatios.size(); ++i) {
nuclear@0 438 out[i] = in.DirectionRatios[i];
nuclear@0 439 }
nuclear@0 440 const IfcFloat len = out.Length();
nuclear@0 441 if (len<1e-6) {
nuclear@0 442 IFCImporter::LogWarn("direction vector magnitude too small, normalization would result in a division by zero");
nuclear@0 443 return;
nuclear@0 444 }
nuclear@0 445 out /= len;
nuclear@0 446 }
nuclear@0 447
nuclear@0 448 // ------------------------------------------------------------------------------------------------
nuclear@0 449 void AssignMatrixAxes(IfcMatrix4& out, const IfcVector3& x, const IfcVector3& y, const IfcVector3& z)
nuclear@0 450 {
nuclear@0 451 out.a1 = x.x;
nuclear@0 452 out.b1 = x.y;
nuclear@0 453 out.c1 = x.z;
nuclear@0 454
nuclear@0 455 out.a2 = y.x;
nuclear@0 456 out.b2 = y.y;
nuclear@0 457 out.c2 = y.z;
nuclear@0 458
nuclear@0 459 out.a3 = z.x;
nuclear@0 460 out.b3 = z.y;
nuclear@0 461 out.c3 = z.z;
nuclear@0 462 }
nuclear@0 463
nuclear@0 464 // ------------------------------------------------------------------------------------------------
nuclear@0 465 void ConvertAxisPlacement(IfcMatrix4& out, const IfcAxis2Placement3D& in)
nuclear@0 466 {
nuclear@0 467 IfcVector3 loc;
nuclear@0 468 ConvertCartesianPoint(loc,in.Location);
nuclear@0 469
nuclear@0 470 IfcVector3 z(0.f,0.f,1.f),r(1.f,0.f,0.f),x;
nuclear@0 471
nuclear@0 472 if (in.Axis) {
nuclear@0 473 ConvertDirection(z,*in.Axis.Get());
nuclear@0 474 }
nuclear@0 475 if (in.RefDirection) {
nuclear@0 476 ConvertDirection(r,*in.RefDirection.Get());
nuclear@0 477 }
nuclear@0 478
nuclear@0 479 IfcVector3 v = r.Normalize();
nuclear@0 480 IfcVector3 tmpx = z * (v*z);
nuclear@0 481
nuclear@0 482 x = (v-tmpx).Normalize();
nuclear@0 483 IfcVector3 y = (z^x);
nuclear@0 484
nuclear@0 485 IfcMatrix4::Translation(loc,out);
nuclear@0 486 AssignMatrixAxes(out,x,y,z);
nuclear@0 487 }
nuclear@0 488
nuclear@0 489 // ------------------------------------------------------------------------------------------------
nuclear@0 490 void ConvertAxisPlacement(IfcMatrix4& out, const IfcAxis2Placement2D& in)
nuclear@0 491 {
nuclear@0 492 IfcVector3 loc;
nuclear@0 493 ConvertCartesianPoint(loc,in.Location);
nuclear@0 494
nuclear@0 495 IfcVector3 x(1.f,0.f,0.f);
nuclear@0 496 if (in.RefDirection) {
nuclear@0 497 ConvertDirection(x,*in.RefDirection.Get());
nuclear@0 498 }
nuclear@0 499
nuclear@0 500 const IfcVector3 y = IfcVector3(x.y,-x.x,0.f);
nuclear@0 501
nuclear@0 502 IfcMatrix4::Translation(loc,out);
nuclear@0 503 AssignMatrixAxes(out,x,y,IfcVector3(0.f,0.f,1.f));
nuclear@0 504 }
nuclear@0 505
nuclear@0 506 // ------------------------------------------------------------------------------------------------
nuclear@0 507 void ConvertAxisPlacement(IfcVector3& axis, IfcVector3& pos, const IfcAxis1Placement& in)
nuclear@0 508 {
nuclear@0 509 ConvertCartesianPoint(pos,in.Location);
nuclear@0 510 if (in.Axis) {
nuclear@0 511 ConvertDirection(axis,in.Axis.Get());
nuclear@0 512 }
nuclear@0 513 else {
nuclear@0 514 axis = IfcVector3(0.f,0.f,1.f);
nuclear@0 515 }
nuclear@0 516 }
nuclear@0 517
nuclear@0 518 // ------------------------------------------------------------------------------------------------
nuclear@0 519 void ConvertAxisPlacement(IfcMatrix4& out, const IfcAxis2Placement& in, ConversionData& conv)
nuclear@0 520 {
nuclear@0 521 if(const IfcAxis2Placement3D* pl3 = in.ResolveSelectPtr<IfcAxis2Placement3D>(conv.db)) {
nuclear@0 522 ConvertAxisPlacement(out,*pl3);
nuclear@0 523 }
nuclear@0 524 else if(const IfcAxis2Placement2D* pl2 = in.ResolveSelectPtr<IfcAxis2Placement2D>(conv.db)) {
nuclear@0 525 ConvertAxisPlacement(out,*pl2);
nuclear@0 526 }
nuclear@0 527 else {
nuclear@0 528 IFCImporter::LogWarn("skipping unknown IfcAxis2Placement entity");
nuclear@0 529 }
nuclear@0 530 }
nuclear@0 531
nuclear@0 532 // ------------------------------------------------------------------------------------------------
nuclear@0 533 void ConvertTransformOperator(IfcMatrix4& out, const IfcCartesianTransformationOperator& op)
nuclear@0 534 {
nuclear@0 535 IfcVector3 loc;
nuclear@0 536 ConvertCartesianPoint(loc,op.LocalOrigin);
nuclear@0 537
nuclear@0 538 IfcVector3 x(1.f,0.f,0.f),y(0.f,1.f,0.f),z(0.f,0.f,1.f);
nuclear@0 539 if (op.Axis1) {
nuclear@0 540 ConvertDirection(x,*op.Axis1.Get());
nuclear@0 541 }
nuclear@0 542 if (op.Axis2) {
nuclear@0 543 ConvertDirection(y,*op.Axis2.Get());
nuclear@0 544 }
nuclear@0 545 if (const IfcCartesianTransformationOperator3D* op2 = op.ToPtr<IfcCartesianTransformationOperator3D>()) {
nuclear@0 546 if(op2->Axis3) {
nuclear@0 547 ConvertDirection(z,*op2->Axis3.Get());
nuclear@0 548 }
nuclear@0 549 }
nuclear@0 550
nuclear@0 551 IfcMatrix4 locm;
nuclear@0 552 IfcMatrix4::Translation(loc,locm);
nuclear@0 553 AssignMatrixAxes(out,x,y,z);
nuclear@0 554
nuclear@0 555
nuclear@0 556 IfcVector3 vscale;
nuclear@0 557 if (const IfcCartesianTransformationOperator3DnonUniform* nuni = op.ToPtr<IfcCartesianTransformationOperator3DnonUniform>()) {
nuclear@0 558 vscale.x = nuni->Scale?op.Scale.Get():1.f;
nuclear@0 559 vscale.y = nuni->Scale2?nuni->Scale2.Get():1.f;
nuclear@0 560 vscale.z = nuni->Scale3?nuni->Scale3.Get():1.f;
nuclear@0 561 }
nuclear@0 562 else {
nuclear@0 563 const IfcFloat sc = op.Scale?op.Scale.Get():1.f;
nuclear@0 564 vscale = IfcVector3(sc,sc,sc);
nuclear@0 565 }
nuclear@0 566
nuclear@0 567 IfcMatrix4 s;
nuclear@0 568 IfcMatrix4::Scaling(vscale,s);
nuclear@0 569
nuclear@0 570 out = locm * out * s;
nuclear@0 571 }
nuclear@0 572
nuclear@0 573
nuclear@0 574 } // ! IFC
nuclear@0 575 } // ! Assimp
nuclear@0 576
nuclear@0 577 #endif