You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

190 lines
7.3 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file IFCProfile.cpp
  34. * @brief Read profile and curves entities from IFC files
  35. */
  36. #include "AssimpPCH.h"
  37. #ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
  38. #include "IFCUtil.h"
  39. namespace Assimp {
  40. namespace IFC {
  41. // ------------------------------------------------------------------------------------------------
  42. void ProcessPolyLine(const IfcPolyline& def, TempMesh& meshout, ConversionData& /*conv*/)
  43. {
  44. // this won't produce a valid mesh, it just spits out a list of vertices
  45. IfcVector3 t;
  46. BOOST_FOREACH(const IfcCartesianPoint& cp, def.Points) {
  47. ConvertCartesianPoint(t,cp);
  48. meshout.verts.push_back(t);
  49. }
  50. meshout.vertcnt.push_back(meshout.verts.size());
  51. }
  52. // ------------------------------------------------------------------------------------------------
  53. bool ProcessCurve(const IfcCurve& curve, TempMesh& meshout, ConversionData& conv)
  54. {
  55. boost::scoped_ptr<const Curve> cv(Curve::Convert(curve,conv));
  56. if (!cv) {
  57. IFCImporter::LogWarn("skipping unknown IfcCurve entity, type is " + curve.GetClassName());
  58. return false;
  59. }
  60. // we must have a bounded curve at this point
  61. if (const BoundedCurve* bc = dynamic_cast<const BoundedCurve*>(cv.get())) {
  62. try {
  63. bc->SampleDiscrete(meshout);
  64. }
  65. catch(const CurveError& cv) {
  66. IFCImporter::LogError(cv.s+ " (error occurred while processing curve)");
  67. return false;
  68. }
  69. meshout.vertcnt.push_back(meshout.verts.size());
  70. return true;
  71. }
  72. IFCImporter::LogError("cannot use unbounded curve as profile");
  73. return false;
  74. }
  75. // ------------------------------------------------------------------------------------------------
  76. void ProcessClosedProfile(const IfcArbitraryClosedProfileDef& def, TempMesh& meshout, ConversionData& conv)
  77. {
  78. ProcessCurve(def.OuterCurve,meshout,conv);
  79. }
  80. // ------------------------------------------------------------------------------------------------
  81. void ProcessOpenProfile(const IfcArbitraryOpenProfileDef& def, TempMesh& meshout, ConversionData& conv)
  82. {
  83. ProcessCurve(def.Curve,meshout,conv);
  84. }
  85. // ------------------------------------------------------------------------------------------------
  86. void ProcessParametrizedProfile(const IfcParameterizedProfileDef& def, TempMesh& meshout, ConversionData& conv)
  87. {
  88. if(const IfcRectangleProfileDef* const cprofile = def.ToPtr<IfcRectangleProfileDef>()) {
  89. const IfcFloat x = cprofile->XDim*0.5f, y = cprofile->YDim*0.5f;
  90. meshout.verts.reserve(meshout.verts.size()+4);
  91. meshout.verts.push_back( IfcVector3( x, y, 0.f ));
  92. meshout.verts.push_back( IfcVector3(-x, y, 0.f ));
  93. meshout.verts.push_back( IfcVector3(-x,-y, 0.f ));
  94. meshout.verts.push_back( IfcVector3( x,-y, 0.f ));
  95. meshout.vertcnt.push_back(4);
  96. }
  97. else if( const IfcCircleProfileDef* const circle = def.ToPtr<IfcCircleProfileDef>()) {
  98. if( const IfcCircleHollowProfileDef* const hollow = def.ToPtr<IfcCircleHollowProfileDef>()) {
  99. // TODO
  100. }
  101. const size_t segments = 32;
  102. const IfcFloat delta = AI_MATH_TWO_PI_F/segments, radius = circle->Radius;
  103. meshout.verts.reserve(segments);
  104. IfcFloat angle = 0.f;
  105. for(size_t i = 0; i < segments; ++i, angle += delta) {
  106. meshout.verts.push_back( IfcVector3( cos(angle)*radius, sin(angle)*radius, 0.f ));
  107. }
  108. meshout.vertcnt.push_back(segments);
  109. }
  110. else if( const IfcIShapeProfileDef* const ishape = def.ToPtr<IfcIShapeProfileDef>()) {
  111. // construct simplified IBeam shape
  112. const IfcFloat offset = (ishape->OverallWidth - ishape->WebThickness) / 2;
  113. const IfcFloat inner_height = ishape->OverallDepth - ishape->FlangeThickness * 2;
  114. meshout.verts.reserve(12);
  115. meshout.verts.push_back(IfcVector3(0,0,0));
  116. meshout.verts.push_back(IfcVector3(0,ishape->FlangeThickness,0));
  117. meshout.verts.push_back(IfcVector3(offset,ishape->FlangeThickness,0));
  118. meshout.verts.push_back(IfcVector3(offset,ishape->FlangeThickness + inner_height,0));
  119. meshout.verts.push_back(IfcVector3(0,ishape->FlangeThickness + inner_height,0));
  120. meshout.verts.push_back(IfcVector3(0,ishape->OverallDepth,0));
  121. meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->OverallDepth,0));
  122. meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->FlangeThickness + inner_height,0));
  123. meshout.verts.push_back(IfcVector3(offset+ishape->WebThickness,ishape->FlangeThickness + inner_height,0));
  124. meshout.verts.push_back(IfcVector3(offset+ishape->WebThickness,ishape->FlangeThickness,0));
  125. meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->FlangeThickness,0));
  126. meshout.verts.push_back(IfcVector3(ishape->OverallWidth,0,0));
  127. meshout.vertcnt.push_back(12);
  128. }
  129. else {
  130. IFCImporter::LogWarn("skipping unknown IfcParameterizedProfileDef entity, type is " + def.GetClassName());
  131. return;
  132. }
  133. IfcMatrix4 trafo;
  134. ConvertAxisPlacement(trafo, *def.Position);
  135. meshout.Transform(trafo);
  136. }
  137. // ------------------------------------------------------------------------------------------------
  138. bool ProcessProfile(const IfcProfileDef& prof, TempMesh& meshout, ConversionData& conv)
  139. {
  140. if(const IfcArbitraryClosedProfileDef* const cprofile = prof.ToPtr<IfcArbitraryClosedProfileDef>()) {
  141. ProcessClosedProfile(*cprofile,meshout,conv);
  142. }
  143. else if(const IfcArbitraryOpenProfileDef* const copen = prof.ToPtr<IfcArbitraryOpenProfileDef>()) {
  144. ProcessOpenProfile(*copen,meshout,conv);
  145. }
  146. else if(const IfcParameterizedProfileDef* const cparam = prof.ToPtr<IfcParameterizedProfileDef>()) {
  147. ProcessParametrizedProfile(*cparam,meshout,conv);
  148. }
  149. else {
  150. IFCImporter::LogWarn("skipping unknown IfcProfileDef entity, type is " + prof.GetClassName());
  151. return false;
  152. }
  153. meshout.RemoveAdjacentDuplicates();
  154. if (!meshout.vertcnt.size() || meshout.vertcnt.front() <= 1) {
  155. return false;
  156. }
  157. return true;
  158. }
  159. } // ! IFC
  160. } // ! Assimp
  161. #endif