IFCCurve.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. namespace {
  42. // --------------------------------------------------------------------------------
  43. // Conic is the base class for Circle and Ellipse
  44. // --------------------------------------------------------------------------------
  45. class Conic : public Curve
  46. {
  47. public:
  48. // --------------------------------------------------
  49. Conic(const IfcConic& entity, ConversionData& conv)
  50. : Curve(entity,conv)
  51. {
  52. IfcMatrix4 trafo;
  53. ConvertAxisPlacement(trafo,*entity.Position,conv);
  54. // for convenience, extract the matrix rows
  55. location = IfcVector3(trafo.a4,trafo.b4,trafo.c4);
  56. p[0] = IfcVector3(trafo.a1,trafo.b1,trafo.c1);
  57. p[1] = IfcVector3(trafo.a2,trafo.b2,trafo.c2);
  58. p[2] = IfcVector3(trafo.a3,trafo.b3,trafo.c3);
  59. }
  60. public:
  61. // --------------------------------------------------
  62. bool IsClosed() const {
  63. return true;
  64. }
  65. // --------------------------------------------------
  66. size_t EstimateSampleCount(IfcFloat a, IfcFloat b) const {
  67. ai_assert(InRange(a) && InRange(b));
  68. a *= conv.angle_scale;
  69. b *= conv.angle_scale;
  70. a = fmod(a,static_cast<IfcFloat>( AI_MATH_TWO_PI ));
  71. b = fmod(b,static_cast<IfcFloat>( AI_MATH_TWO_PI ));
  72. const IfcFloat setting = static_cast<IfcFloat>( AI_MATH_PI * conv.settings.conicSamplingAngle / 180.0 );
  73. return static_cast<size_t>( ceil(abs( b-a)) / setting);
  74. }
  75. // --------------------------------------------------
  76. ParamRange GetParametricRange() const {
  77. return std::make_pair(static_cast<IfcFloat>( 0. ), static_cast<IfcFloat>( AI_MATH_TWO_PI / conv.angle_scale ));
  78. }
  79. protected:
  80. IfcVector3 location, p[3];
  81. };
  82. // --------------------------------------------------------------------------------
  83. // Circle
  84. // --------------------------------------------------------------------------------
  85. class Circle : public Conic
  86. {
  87. public:
  88. // --------------------------------------------------
  89. Circle(const IfcCircle& entity, ConversionData& conv)
  90. : Conic(entity,conv)
  91. , entity(entity)
  92. {
  93. }
  94. public:
  95. // --------------------------------------------------
  96. IfcVector3 Eval(IfcFloat u) const {
  97. u = -conv.angle_scale * u;
  98. return location + static_cast<IfcFloat>(entity.Radius)*(static_cast<IfcFloat>(::cos(u))*p[0] +
  99. static_cast<IfcFloat>(::sin(u))*p[1]);
  100. }
  101. private:
  102. const IfcCircle& entity;
  103. };
  104. // --------------------------------------------------------------------------------
  105. // Ellipse
  106. // --------------------------------------------------------------------------------
  107. class Ellipse : public Conic
  108. {
  109. public:
  110. // --------------------------------------------------
  111. Ellipse(const IfcEllipse& entity, ConversionData& conv)
  112. : Conic(entity,conv)
  113. , entity(entity)
  114. {
  115. }
  116. public:
  117. // --------------------------------------------------
  118. IfcVector3 Eval(IfcFloat u) const {
  119. u = -conv.angle_scale * u;
  120. return location + static_cast<IfcFloat>(entity.SemiAxis1)*static_cast<IfcFloat>(::cos(u))*p[0] +
  121. static_cast<IfcFloat>(entity.SemiAxis2)*static_cast<IfcFloat>(::sin(u))*p[1];
  122. }
  123. private:
  124. const IfcEllipse& entity;
  125. };
  126. // --------------------------------------------------------------------------------
  127. // Line
  128. // --------------------------------------------------------------------------------
  129. class Line : public Curve
  130. {
  131. public:
  132. // --------------------------------------------------
  133. Line(const IfcLine& entity, ConversionData& conv)
  134. : Curve(entity,conv)
  135. , entity(entity)
  136. {
  137. ConvertCartesianPoint(p,entity.Pnt);
  138. ConvertVector(v,entity.Dir);
  139. }
  140. public:
  141. // --------------------------------------------------
  142. bool IsClosed() const {
  143. return false;
  144. }
  145. // --------------------------------------------------
  146. IfcVector3 Eval(IfcFloat u) const {
  147. return p + u*v;
  148. }
  149. // --------------------------------------------------
  150. size_t EstimateSampleCount(IfcFloat a, IfcFloat b) const {
  151. ai_assert(InRange(a) && InRange(b));
  152. // two points are always sufficient for a line segment
  153. return a==b ? 1 : 2;
  154. }
  155. // --------------------------------------------------
  156. void SampleDiscrete(TempMesh& out,IfcFloat a, IfcFloat b) const
  157. {
  158. ai_assert(InRange(a) && InRange(b));
  159. if (a == b) {
  160. out.verts.push_back(Eval(a));
  161. return;
  162. }
  163. out.verts.reserve(out.verts.size()+2);
  164. out.verts.push_back(Eval(a));
  165. out.verts.push_back(Eval(b));
  166. }
  167. // --------------------------------------------------
  168. ParamRange GetParametricRange() const {
  169. const IfcFloat inf = std::numeric_limits<IfcFloat>::infinity();
  170. return std::make_pair(-inf,+inf);
  171. }
  172. private:
  173. const IfcLine& entity;
  174. IfcVector3 p,v;
  175. };
  176. // --------------------------------------------------------------------------------
  177. // CompositeCurve joins multiple smaller, bounded curves
  178. // --------------------------------------------------------------------------------
  179. class CompositeCurve : public BoundedCurve
  180. {
  181. typedef std::pair< boost::shared_ptr< BoundedCurve >, bool > CurveEntry;
  182. public:
  183. // --------------------------------------------------
  184. CompositeCurve(const IfcCompositeCurve& entity, ConversionData& conv)
  185. : BoundedCurve(entity,conv)
  186. , entity(entity)
  187. , total()
  188. {
  189. curves.reserve(entity.Segments.size());
  190. BOOST_FOREACH(const IfcCompositeCurveSegment& curveSegment,entity.Segments) {
  191. // according to the specification, this must be a bounded curve
  192. boost::shared_ptr< Curve > cv(Curve::Convert(curveSegment.ParentCurve,conv));
  193. boost::shared_ptr< BoundedCurve > bc = boost::dynamic_pointer_cast<BoundedCurve>(cv);
  194. if (!bc) {
  195. IFCImporter::LogError("expected segment of composite curve to be a bounded curve");
  196. continue;
  197. }
  198. if ( (std::string)curveSegment.Transition != "CONTINUOUS" ) {
  199. IFCImporter::LogDebug("ignoring transition code on composite curve segment, only continuous transitions are supported");
  200. }
  201. curves.push_back( CurveEntry(bc,IsTrue(curveSegment.SameSense)) );
  202. total += bc->GetParametricRangeDelta();
  203. }
  204. if (curves.empty()) {
  205. throw CurveError("empty composite curve");
  206. }
  207. }
  208. public:
  209. // --------------------------------------------------
  210. IfcVector3 Eval(IfcFloat u) const {
  211. if (curves.empty()) {
  212. return IfcVector3();
  213. }
  214. IfcFloat acc = 0;
  215. BOOST_FOREACH(const CurveEntry& entry, curves) {
  216. const ParamRange& range = entry.first->GetParametricRange();
  217. const IfcFloat delta = abs(range.second-range.first);
  218. if (u < acc+delta) {
  219. return entry.first->Eval( entry.second ? (u-acc) + range.first : range.second-(u-acc));
  220. }
  221. acc += delta;
  222. }
  223. // clamp to end
  224. return curves.back().first->Eval(curves.back().first->GetParametricRange().second);
  225. }
  226. // --------------------------------------------------
  227. size_t EstimateSampleCount(IfcFloat a, IfcFloat b) const {
  228. ai_assert(InRange(a) && InRange(b));
  229. size_t cnt = 0;
  230. IfcFloat acc = 0;
  231. BOOST_FOREACH(const CurveEntry& entry, curves) {
  232. const ParamRange& range = entry.first->GetParametricRange();
  233. const IfcFloat delta = abs(range.second-range.first);
  234. if (a <= acc+delta && b >= acc) {
  235. const IfcFloat at = std::max(static_cast<IfcFloat>( 0. ),a-acc), bt = std::min(delta,b-acc);
  236. cnt += entry.first->EstimateSampleCount( entry.second ? at + range.first : range.second - bt, entry.second ? bt + range.first : range.second - at );
  237. }
  238. acc += delta;
  239. }
  240. return cnt;
  241. }
  242. // --------------------------------------------------
  243. void SampleDiscrete(TempMesh& out,IfcFloat a, IfcFloat b) const
  244. {
  245. ai_assert(InRange(a) && InRange(b));
  246. const size_t cnt = EstimateSampleCount(a,b);
  247. out.verts.reserve(out.verts.size() + cnt);
  248. BOOST_FOREACH(const CurveEntry& entry, curves) {
  249. const size_t cnt = out.verts.size();
  250. entry.first->SampleDiscrete(out);
  251. if (!entry.second && cnt != out.verts.size()) {
  252. std::reverse(out.verts.begin()+cnt,out.verts.end());
  253. }
  254. }
  255. }
  256. // --------------------------------------------------
  257. ParamRange GetParametricRange() const {
  258. return std::make_pair(static_cast<IfcFloat>( 0. ),total);
  259. }
  260. private:
  261. const IfcCompositeCurve& entity;
  262. std::vector< CurveEntry > curves;
  263. IfcFloat total;
  264. };
  265. // --------------------------------------------------------------------------------
  266. // TrimmedCurve can be used to trim an unbounded curve to a bounded range
  267. // --------------------------------------------------------------------------------
  268. class TrimmedCurve : public BoundedCurve
  269. {
  270. public:
  271. // --------------------------------------------------
  272. TrimmedCurve(const IfcTrimmedCurve& entity, ConversionData& conv)
  273. : BoundedCurve(entity,conv)
  274. , entity(entity)
  275. , ok()
  276. {
  277. base = boost::shared_ptr<const Curve>(Curve::Convert(entity.BasisCurve,conv));
  278. typedef boost::shared_ptr<const STEP::EXPRESS::DataType> Entry;
  279. // for some reason, trimmed curves can either specify a parametric value
  280. // or a point on the curve, or both. And they can even specify which of the
  281. // two representations they prefer, even though an information invariant
  282. // claims that they must be identical if both are present.
  283. // oh well.
  284. bool have_param = false, have_point = false;
  285. IfcVector3 point;
  286. BOOST_FOREACH(const Entry sel,entity.Trim1) {
  287. if (const EXPRESS::REAL* const r = sel->ToPtr<EXPRESS::REAL>()) {
  288. range.first = *r;
  289. have_param = true;
  290. break;
  291. }
  292. else if (const IfcCartesianPoint* const r = sel->ResolveSelectPtr<IfcCartesianPoint>(conv.db)) {
  293. ConvertCartesianPoint(point,*r);
  294. have_point = true;
  295. }
  296. }
  297. if (!have_param) {
  298. if (!have_point || !base->ReverseEval(point,range.first)) {
  299. throw CurveError("IfcTrimmedCurve: failed to read first trim parameter, ignoring curve");
  300. }
  301. }
  302. have_param = false, have_point = false;
  303. BOOST_FOREACH(const Entry sel,entity.Trim2) {
  304. if (const EXPRESS::REAL* const r = sel->ToPtr<EXPRESS::REAL>()) {
  305. range.second = *r;
  306. have_param = true;
  307. break;
  308. }
  309. else if (const IfcCartesianPoint* const r = sel->ResolveSelectPtr<IfcCartesianPoint>(conv.db)) {
  310. ConvertCartesianPoint(point,*r);
  311. have_point = true;
  312. }
  313. }
  314. if (!have_param) {
  315. if (!have_point || !base->ReverseEval(point,range.second)) {
  316. throw CurveError("IfcTrimmedCurve: failed to read second trim parameter, ignoring curve");
  317. }
  318. }
  319. agree_sense = IsTrue(entity.SenseAgreement);
  320. if( !agree_sense ) {
  321. std::swap(range.first,range.second);
  322. }
  323. // "NOTE In case of a closed curve, it may be necessary to increment t1 or t2
  324. // by the parametric length for consistency with the sense flag."
  325. if (base->IsClosed()) {
  326. if( range.first > range.second ) {
  327. range.second += base->GetParametricRangeDelta();
  328. }
  329. }
  330. maxval = range.second-range.first;
  331. ai_assert(maxval >= 0);
  332. }
  333. public:
  334. // --------------------------------------------------
  335. IfcVector3 Eval(IfcFloat p) const {
  336. ai_assert(InRange(p));
  337. return base->Eval( TrimParam(p) );
  338. }
  339. // --------------------------------------------------
  340. size_t EstimateSampleCount(IfcFloat a, IfcFloat b) const {
  341. ai_assert(InRange(a) && InRange(b));
  342. return base->EstimateSampleCount(TrimParam(a),TrimParam(b));
  343. }
  344. // --------------------------------------------------
  345. void SampleDiscrete(TempMesh& out,IfcFloat a,IfcFloat b) const {
  346. ai_assert(InRange(a) && InRange(b));
  347. return base->SampleDiscrete(out,TrimParam(a),TrimParam(b));
  348. }
  349. // --------------------------------------------------
  350. ParamRange GetParametricRange() const {
  351. return std::make_pair(static_cast<IfcFloat>( 0. ),maxval);
  352. }
  353. private:
  354. // --------------------------------------------------
  355. IfcFloat TrimParam(IfcFloat f) const {
  356. return agree_sense ? f + range.first : range.second - f;
  357. }
  358. private:
  359. const IfcTrimmedCurve& entity;
  360. ParamRange range;
  361. IfcFloat maxval;
  362. bool agree_sense;
  363. bool ok;
  364. boost::shared_ptr<const Curve> base;
  365. };
  366. // --------------------------------------------------------------------------------
  367. // PolyLine is a 'curve' defined by linear interpolation over a set of discrete points
  368. // --------------------------------------------------------------------------------
  369. class PolyLine : public BoundedCurve
  370. {
  371. public:
  372. // --------------------------------------------------
  373. PolyLine(const IfcPolyline& entity, ConversionData& conv)
  374. : BoundedCurve(entity,conv)
  375. , entity(entity)
  376. {
  377. points.reserve(entity.Points.size());
  378. IfcVector3 t;
  379. BOOST_FOREACH(const IfcCartesianPoint& cp, entity.Points) {
  380. ConvertCartesianPoint(t,cp);
  381. points.push_back(t);
  382. }
  383. }
  384. public:
  385. // --------------------------------------------------
  386. IfcVector3 Eval(IfcFloat p) const {
  387. ai_assert(InRange(p));
  388. const size_t b = static_cast<size_t>(floor(p));
  389. if (b == points.size()-1) {
  390. return points.back();
  391. }
  392. const IfcFloat d = p-static_cast<IfcFloat>(b);
  393. return points[b+1] * d + points[b] * (static_cast<IfcFloat>( 1. )-d);
  394. }
  395. // --------------------------------------------------
  396. size_t EstimateSampleCount(IfcFloat a, IfcFloat b) const {
  397. ai_assert(InRange(a) && InRange(b));
  398. return static_cast<size_t>( ceil(b) - floor(a) );
  399. }
  400. // --------------------------------------------------
  401. ParamRange GetParametricRange() const {
  402. return std::make_pair(static_cast<IfcFloat>( 0. ),static_cast<IfcFloat>(points.size()-1));
  403. }
  404. private:
  405. const IfcPolyline& entity;
  406. std::vector<IfcVector3> points;
  407. };
  408. } // anon
  409. // ------------------------------------------------------------------------------------------------
  410. Curve* Curve :: Convert(const IFC::IfcCurve& curve,ConversionData& conv)
  411. {
  412. if(curve.ToPtr<IfcBoundedCurve>()) {
  413. if(const IfcPolyline* c = curve.ToPtr<IfcPolyline>()) {
  414. return new PolyLine(*c,conv);
  415. }
  416. if(const IfcTrimmedCurve* c = curve.ToPtr<IfcTrimmedCurve>()) {
  417. return new TrimmedCurve(*c,conv);
  418. }
  419. if(const IfcCompositeCurve* c = curve.ToPtr<IfcCompositeCurve>()) {
  420. return new CompositeCurve(*c,conv);
  421. }
  422. //if(const IfcBSplineCurve* c = curve.ToPtr<IfcBSplineCurve>()) {
  423. // return new BSplineCurve(*c,conv);
  424. //}
  425. }
  426. if(curve.ToPtr<IfcConic>()) {
  427. if(const IfcCircle* c = curve.ToPtr<IfcCircle>()) {
  428. return new Circle(*c,conv);
  429. }
  430. if(const IfcEllipse* c = curve.ToPtr<IfcEllipse>()) {
  431. return new Ellipse(*c,conv);
  432. }
  433. }
  434. if(const IfcLine* c = curve.ToPtr<IfcLine>()) {
  435. return new Line(*c,conv);
  436. }
  437. // XXX OffsetCurve2D, OffsetCurve3D not currently supported
  438. return NULL;
  439. }
  440. #ifdef _DEBUG
  441. // ------------------------------------------------------------------------------------------------
  442. bool Curve :: InRange(IfcFloat u) const
  443. {
  444. const ParamRange range = GetParametricRange();
  445. if (IsClosed()) {
  446. return true;
  447. //ai_assert(range.first != std::numeric_limits<IfcFloat>::infinity() && range.second != std::numeric_limits<IfcFloat>::infinity());
  448. //u = range.first + fmod(u-range.first,range.second-range.first);
  449. }
  450. const IfcFloat epsilon = 1e-5;
  451. return u - range.first > -epsilon && range.second - u > -epsilon;
  452. }
  453. #endif
  454. // ------------------------------------------------------------------------------------------------
  455. IfcFloat Curve :: GetParametricRangeDelta() const
  456. {
  457. const ParamRange& range = GetParametricRange();
  458. return abs(range.second - range.first);
  459. }
  460. // ------------------------------------------------------------------------------------------------
  461. size_t Curve :: EstimateSampleCount(IfcFloat a, IfcFloat b) const
  462. {
  463. ai_assert(InRange(a) && InRange(b));
  464. // arbitrary default value, deriving classes should supply better suited values
  465. return 16;
  466. }
  467. // ------------------------------------------------------------------------------------------------
  468. IfcFloat RecursiveSearch(const Curve* cv, const IfcVector3& val, IfcFloat a, IfcFloat b, unsigned int samples, IfcFloat threshold, unsigned int recurse = 0, unsigned int max_recurse = 15)
  469. {
  470. ai_assert(samples>1);
  471. const IfcFloat delta = (b-a)/samples, inf = std::numeric_limits<IfcFloat>::infinity();
  472. IfcFloat min_point[2] = {a,b}, min_diff[2] = {inf,inf};
  473. IfcFloat runner = a;
  474. for (unsigned int i = 0; i < samples; ++i, runner += delta) {
  475. const IfcFloat diff = (cv->Eval(runner)-val).SquareLength();
  476. if (diff < min_diff[0]) {
  477. min_diff[1] = min_diff[0];
  478. min_point[1] = min_point[0];
  479. min_diff[0] = diff;
  480. min_point[0] = runner;
  481. }
  482. else if (diff < min_diff[1]) {
  483. min_diff[1] = diff;
  484. min_point[1] = runner;
  485. }
  486. }
  487. ai_assert(min_diff[0] != inf && min_diff[1] != inf);
  488. if ( fabs(a-min_point[0]) < threshold || recurse >= max_recurse) {
  489. return min_point[0];
  490. }
  491. // fix for closed curves to take their wrap-over into account
  492. if (cv->IsClosed() && fabs(min_point[0]-min_point[1]) > cv->GetParametricRangeDelta()*0.5 ) {
  493. const Curve::ParamRange& range = cv->GetParametricRange();
  494. const IfcFloat wrapdiff = (cv->Eval(range.first)-val).SquareLength();
  495. if (wrapdiff < min_diff[0]) {
  496. const IfcFloat t = min_point[0];
  497. min_point[0] = min_point[1] > min_point[0] ? range.first : range.second;
  498. min_point[1] = t;
  499. }
  500. }
  501. return RecursiveSearch(cv,val,min_point[0],min_point[1],samples,threshold,recurse+1,max_recurse);
  502. }
  503. // ------------------------------------------------------------------------------------------------
  504. bool Curve :: ReverseEval(const IfcVector3& val, IfcFloat& paramOut) const
  505. {
  506. // note: the following algorithm is not guaranteed to find the 'right' parameter value
  507. // in all possible cases, but it will always return at least some value so this function
  508. // will never fail in the default implementation.
  509. // XXX derive threshold from curve topology
  510. const IfcFloat threshold = 1e-4f;
  511. const unsigned int samples = 16;
  512. const ParamRange& range = GetParametricRange();
  513. paramOut = RecursiveSearch(this,val,range.first,range.second,samples,threshold);
  514. return true;
  515. }
  516. // ------------------------------------------------------------------------------------------------
  517. void Curve :: SampleDiscrete(TempMesh& out,IfcFloat a, IfcFloat b) const
  518. {
  519. ai_assert(InRange(a) && InRange(b));
  520. const size_t cnt = std::max(static_cast<size_t>(0),EstimateSampleCount(a,b));
  521. out.verts.reserve( out.verts.size() + cnt );
  522. IfcFloat p = a, delta = (b-a)/cnt;
  523. for(size_t i = 0; i < cnt; ++i, p += delta) {
  524. out.verts.push_back(Eval(p));
  525. }
  526. }
  527. // ------------------------------------------------------------------------------------------------
  528. bool BoundedCurve :: IsClosed() const
  529. {
  530. return false;
  531. }
  532. // ------------------------------------------------------------------------------------------------
  533. void BoundedCurve :: SampleDiscrete(TempMesh& out) const
  534. {
  535. const ParamRange& range = GetParametricRange();
  536. ai_assert(range.first != std::numeric_limits<IfcFloat>::infinity() && range.second != std::numeric_limits<IfcFloat>::infinity());
  537. return SampleDiscrete(out,range.first,range.second);
  538. }
  539. } // IFC
  540. } // Assimp
  541. #endif // ASSIMP_BUILD_NO_IFC_IMPORTER