IFCCurve.cpp 22 KB

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