IFCCurve.cpp 23 KB

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