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