nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file IFCProfile.cpp nuclear@0: * @brief Read profile and curves entities from IFC files nuclear@0: */ nuclear@0: nuclear@0: #include "AssimpPCH.h" nuclear@0: nuclear@0: #ifndef ASSIMP_BUILD_NO_IFC_IMPORTER nuclear@0: #include "IFCUtil.h" nuclear@0: nuclear@0: namespace Assimp { nuclear@0: namespace IFC { nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: void ProcessPolyLine(const IfcPolyline& def, TempMesh& meshout, ConversionData& /*conv*/) nuclear@0: { nuclear@0: // this won't produce a valid mesh, it just spits out a list of vertices nuclear@0: IfcVector3 t; nuclear@0: BOOST_FOREACH(const IfcCartesianPoint& cp, def.Points) { nuclear@0: ConvertCartesianPoint(t,cp); nuclear@0: meshout.verts.push_back(t); nuclear@0: } nuclear@0: meshout.vertcnt.push_back(meshout.verts.size()); nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: bool ProcessCurve(const IfcCurve& curve, TempMesh& meshout, ConversionData& conv) nuclear@0: { nuclear@0: boost::scoped_ptr cv(Curve::Convert(curve,conv)); nuclear@0: if (!cv) { nuclear@0: IFCImporter::LogWarn("skipping unknown IfcCurve entity, type is " + curve.GetClassName()); nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: // we must have a bounded curve at this point nuclear@0: if (const BoundedCurve* bc = dynamic_cast(cv.get())) { nuclear@0: try { nuclear@0: bc->SampleDiscrete(meshout); nuclear@0: } nuclear@0: catch(const CurveError& cv) { nuclear@0: IFCImporter::LogError(cv.s+ " (error occurred while processing curve)"); nuclear@0: return false; nuclear@0: } nuclear@0: meshout.vertcnt.push_back(meshout.verts.size()); nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: IFCImporter::LogError("cannot use unbounded curve as profile"); nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: void ProcessClosedProfile(const IfcArbitraryClosedProfileDef& def, TempMesh& meshout, ConversionData& conv) nuclear@0: { nuclear@0: ProcessCurve(def.OuterCurve,meshout,conv); nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: void ProcessOpenProfile(const IfcArbitraryOpenProfileDef& def, TempMesh& meshout, ConversionData& conv) nuclear@0: { nuclear@0: ProcessCurve(def.Curve,meshout,conv); nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: void ProcessParametrizedProfile(const IfcParameterizedProfileDef& def, TempMesh& meshout, ConversionData& conv) nuclear@0: { nuclear@0: if(const IfcRectangleProfileDef* const cprofile = def.ToPtr()) { nuclear@0: const IfcFloat x = cprofile->XDim*0.5f, y = cprofile->YDim*0.5f; nuclear@0: nuclear@0: meshout.verts.reserve(meshout.verts.size()+4); nuclear@0: meshout.verts.push_back( IfcVector3( x, y, 0.f )); nuclear@0: meshout.verts.push_back( IfcVector3(-x, y, 0.f )); nuclear@0: meshout.verts.push_back( IfcVector3(-x,-y, 0.f )); nuclear@0: meshout.verts.push_back( IfcVector3( x,-y, 0.f )); nuclear@0: meshout.vertcnt.push_back(4); nuclear@0: } nuclear@0: else if( const IfcCircleProfileDef* const circle = def.ToPtr()) { nuclear@0: if( const IfcCircleHollowProfileDef* const hollow = def.ToPtr()) { nuclear@0: // TODO nuclear@0: } nuclear@0: const size_t segments = 32; nuclear@0: const IfcFloat delta = AI_MATH_TWO_PI_F/segments, radius = circle->Radius; nuclear@0: nuclear@0: meshout.verts.reserve(segments); nuclear@0: nuclear@0: IfcFloat angle = 0.f; nuclear@0: for(size_t i = 0; i < segments; ++i, angle += delta) { nuclear@0: meshout.verts.push_back( IfcVector3( cos(angle)*radius, sin(angle)*radius, 0.f )); nuclear@0: } nuclear@0: nuclear@0: meshout.vertcnt.push_back(segments); nuclear@0: } nuclear@0: else if( const IfcIShapeProfileDef* const ishape = def.ToPtr()) { nuclear@0: // construct simplified IBeam shape nuclear@0: const IfcFloat offset = (ishape->OverallWidth - ishape->WebThickness) / 2; nuclear@0: const IfcFloat inner_height = ishape->OverallDepth - ishape->FlangeThickness * 2; nuclear@0: nuclear@0: meshout.verts.reserve(12); nuclear@0: meshout.verts.push_back(IfcVector3(0,0,0)); nuclear@0: meshout.verts.push_back(IfcVector3(0,ishape->FlangeThickness,0)); nuclear@0: meshout.verts.push_back(IfcVector3(offset,ishape->FlangeThickness,0)); nuclear@0: meshout.verts.push_back(IfcVector3(offset,ishape->FlangeThickness + inner_height,0)); nuclear@0: meshout.verts.push_back(IfcVector3(0,ishape->FlangeThickness + inner_height,0)); nuclear@0: meshout.verts.push_back(IfcVector3(0,ishape->OverallDepth,0)); nuclear@0: meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->OverallDepth,0)); nuclear@0: meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->FlangeThickness + inner_height,0)); nuclear@0: meshout.verts.push_back(IfcVector3(offset+ishape->WebThickness,ishape->FlangeThickness + inner_height,0)); nuclear@0: meshout.verts.push_back(IfcVector3(offset+ishape->WebThickness,ishape->FlangeThickness,0)); nuclear@0: meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->FlangeThickness,0)); nuclear@0: meshout.verts.push_back(IfcVector3(ishape->OverallWidth,0,0)); nuclear@0: nuclear@0: meshout.vertcnt.push_back(12); nuclear@0: } nuclear@0: else { nuclear@0: IFCImporter::LogWarn("skipping unknown IfcParameterizedProfileDef entity, type is " + def.GetClassName()); nuclear@0: return; nuclear@0: } nuclear@0: nuclear@0: IfcMatrix4 trafo; nuclear@0: ConvertAxisPlacement(trafo, *def.Position); nuclear@0: meshout.Transform(trafo); nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: bool ProcessProfile(const IfcProfileDef& prof, TempMesh& meshout, ConversionData& conv) nuclear@0: { nuclear@0: if(const IfcArbitraryClosedProfileDef* const cprofile = prof.ToPtr()) { nuclear@0: ProcessClosedProfile(*cprofile,meshout,conv); nuclear@0: } nuclear@0: else if(const IfcArbitraryOpenProfileDef* const copen = prof.ToPtr()) { nuclear@0: ProcessOpenProfile(*copen,meshout,conv); nuclear@0: } nuclear@0: else if(const IfcParameterizedProfileDef* const cparam = prof.ToPtr()) { nuclear@0: ProcessParametrizedProfile(*cparam,meshout,conv); nuclear@0: } nuclear@0: else { nuclear@0: IFCImporter::LogWarn("skipping unknown IfcProfileDef entity, type is " + prof.GetClassName()); nuclear@0: return false; nuclear@0: } nuclear@0: meshout.RemoveAdjacentDuplicates(); nuclear@0: if (!meshout.vertcnt.size() || meshout.vertcnt.front() <= 1) { nuclear@0: return false; nuclear@0: } nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: } // ! IFC nuclear@0: } // ! Assimp nuclear@0: nuclear@0: #endif