vrshoot

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/IFCProfile.cpp	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,189 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +/** @file  IFCProfile.cpp
    1.45 + *  @brief Read profile and curves entities from IFC files
    1.46 + */
    1.47 +
    1.48 +#include "AssimpPCH.h"
    1.49 +
    1.50 +#ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
    1.51 +#include "IFCUtil.h"
    1.52 +
    1.53 +namespace Assimp {
    1.54 +	namespace IFC {
    1.55 +
    1.56 +// ------------------------------------------------------------------------------------------------
    1.57 +void ProcessPolyLine(const IfcPolyline& def, TempMesh& meshout, ConversionData& /*conv*/)
    1.58 +{
    1.59 +	// this won't produce a valid mesh, it just spits out a list of vertices
    1.60 +	IfcVector3 t;
    1.61 +	BOOST_FOREACH(const IfcCartesianPoint& cp, def.Points) {
    1.62 +		ConvertCartesianPoint(t,cp);
    1.63 +		meshout.verts.push_back(t);
    1.64 +	}
    1.65 +	meshout.vertcnt.push_back(meshout.verts.size());
    1.66 +}
    1.67 +
    1.68 +// ------------------------------------------------------------------------------------------------
    1.69 +bool ProcessCurve(const IfcCurve& curve,  TempMesh& meshout, ConversionData& conv)
    1.70 +{
    1.71 +	boost::scoped_ptr<const Curve> cv(Curve::Convert(curve,conv));
    1.72 +	if (!cv) {
    1.73 +		IFCImporter::LogWarn("skipping unknown IfcCurve entity, type is " + curve.GetClassName());
    1.74 +		return false;
    1.75 +	}
    1.76 +
    1.77 +	// we must have a bounded curve at this point
    1.78 +	if (const BoundedCurve* bc = dynamic_cast<const BoundedCurve*>(cv.get())) {
    1.79 +		try {
    1.80 +			bc->SampleDiscrete(meshout);
    1.81 +		}
    1.82 +		catch(const  CurveError& cv) {
    1.83 +			IFCImporter::LogError(cv.s+ " (error occurred while processing curve)");
    1.84 +			return false;
    1.85 +		}
    1.86 +		meshout.vertcnt.push_back(meshout.verts.size());
    1.87 +		return true;
    1.88 +	}
    1.89 +
    1.90 +	IFCImporter::LogError("cannot use unbounded curve as profile");
    1.91 +	return false;
    1.92 +}
    1.93 +
    1.94 +// ------------------------------------------------------------------------------------------------
    1.95 +void ProcessClosedProfile(const IfcArbitraryClosedProfileDef& def, TempMesh& meshout, ConversionData& conv)
    1.96 +{
    1.97 +	ProcessCurve(def.OuterCurve,meshout,conv);
    1.98 +}
    1.99 +
   1.100 +// ------------------------------------------------------------------------------------------------
   1.101 +void ProcessOpenProfile(const IfcArbitraryOpenProfileDef& def, TempMesh& meshout, ConversionData& conv)
   1.102 +{
   1.103 +	ProcessCurve(def.Curve,meshout,conv);
   1.104 +}
   1.105 +
   1.106 +// ------------------------------------------------------------------------------------------------
   1.107 +void ProcessParametrizedProfile(const IfcParameterizedProfileDef& def, TempMesh& meshout, ConversionData& conv)
   1.108 +{
   1.109 +	if(const IfcRectangleProfileDef* const cprofile = def.ToPtr<IfcRectangleProfileDef>()) {
   1.110 +		const IfcFloat x = cprofile->XDim*0.5f, y = cprofile->YDim*0.5f;
   1.111 +
   1.112 +		meshout.verts.reserve(meshout.verts.size()+4);
   1.113 +		meshout.verts.push_back( IfcVector3( x, y, 0.f ));
   1.114 +		meshout.verts.push_back( IfcVector3(-x, y, 0.f ));
   1.115 +		meshout.verts.push_back( IfcVector3(-x,-y, 0.f ));
   1.116 +		meshout.verts.push_back( IfcVector3( x,-y, 0.f ));
   1.117 +		meshout.vertcnt.push_back(4);
   1.118 +	}
   1.119 +	else if( const IfcCircleProfileDef* const circle = def.ToPtr<IfcCircleProfileDef>()) {
   1.120 +		if( const IfcCircleHollowProfileDef* const hollow = def.ToPtr<IfcCircleHollowProfileDef>()) {
   1.121 +			// TODO
   1.122 +		}
   1.123 +		const size_t segments = 32;
   1.124 +		const IfcFloat delta = AI_MATH_TWO_PI_F/segments, radius = circle->Radius;
   1.125 +
   1.126 +		meshout.verts.reserve(segments);
   1.127 +
   1.128 +		IfcFloat angle = 0.f;
   1.129 +		for(size_t i = 0; i < segments; ++i, angle += delta) {
   1.130 +			meshout.verts.push_back( IfcVector3( cos(angle)*radius, sin(angle)*radius, 0.f ));
   1.131 +		}
   1.132 +
   1.133 +		meshout.vertcnt.push_back(segments);
   1.134 +	}
   1.135 +	else if( const IfcIShapeProfileDef* const ishape = def.ToPtr<IfcIShapeProfileDef>()) {
   1.136 +		// construct simplified IBeam shape
   1.137 +		const IfcFloat offset = (ishape->OverallWidth - ishape->WebThickness) / 2;
   1.138 +		const IfcFloat inner_height = ishape->OverallDepth - ishape->FlangeThickness * 2;
   1.139 +
   1.140 +		meshout.verts.reserve(12);
   1.141 +		meshout.verts.push_back(IfcVector3(0,0,0));
   1.142 +		meshout.verts.push_back(IfcVector3(0,ishape->FlangeThickness,0));
   1.143 +		meshout.verts.push_back(IfcVector3(offset,ishape->FlangeThickness,0));
   1.144 +		meshout.verts.push_back(IfcVector3(offset,ishape->FlangeThickness + inner_height,0));
   1.145 +		meshout.verts.push_back(IfcVector3(0,ishape->FlangeThickness + inner_height,0));
   1.146 +		meshout.verts.push_back(IfcVector3(0,ishape->OverallDepth,0));
   1.147 +		meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->OverallDepth,0));
   1.148 +		meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->FlangeThickness + inner_height,0));
   1.149 +		meshout.verts.push_back(IfcVector3(offset+ishape->WebThickness,ishape->FlangeThickness + inner_height,0));
   1.150 +		meshout.verts.push_back(IfcVector3(offset+ishape->WebThickness,ishape->FlangeThickness,0));
   1.151 +		meshout.verts.push_back(IfcVector3(ishape->OverallWidth,ishape->FlangeThickness,0));
   1.152 +		meshout.verts.push_back(IfcVector3(ishape->OverallWidth,0,0));
   1.153 +
   1.154 +		meshout.vertcnt.push_back(12);
   1.155 +	}
   1.156 +	else {
   1.157 +		IFCImporter::LogWarn("skipping unknown IfcParameterizedProfileDef entity, type is " + def.GetClassName());
   1.158 +		return;
   1.159 +	}
   1.160 +
   1.161 +	IfcMatrix4 trafo;
   1.162 +	ConvertAxisPlacement(trafo, *def.Position);
   1.163 +	meshout.Transform(trafo);
   1.164 +}
   1.165 +
   1.166 +// ------------------------------------------------------------------------------------------------
   1.167 +bool ProcessProfile(const IfcProfileDef& prof, TempMesh& meshout, ConversionData& conv) 
   1.168 +{
   1.169 +	if(const IfcArbitraryClosedProfileDef* const cprofile = prof.ToPtr<IfcArbitraryClosedProfileDef>()) {
   1.170 +		ProcessClosedProfile(*cprofile,meshout,conv);
   1.171 +	}
   1.172 +	else if(const IfcArbitraryOpenProfileDef* const copen = prof.ToPtr<IfcArbitraryOpenProfileDef>()) {
   1.173 +		ProcessOpenProfile(*copen,meshout,conv);
   1.174 +	}
   1.175 +	else if(const IfcParameterizedProfileDef* const cparam = prof.ToPtr<IfcParameterizedProfileDef>()) {
   1.176 +		ProcessParametrizedProfile(*cparam,meshout,conv);
   1.177 +	}
   1.178 +	else {
   1.179 +		IFCImporter::LogWarn("skipping unknown IfcProfileDef entity, type is " + prof.GetClassName());
   1.180 +		return false;
   1.181 +	}
   1.182 +	meshout.RemoveAdjacentDuplicates();
   1.183 +	if (!meshout.vertcnt.size() || meshout.vertcnt.front() <= 1) {
   1.184 +		return false;
   1.185 +	}
   1.186 +	return true;
   1.187 +}
   1.188 +
   1.189 +} // ! IFC
   1.190 +} // ! Assimp
   1.191 +
   1.192 +#endif