2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2020-01-20 13:53:12 +00:00
|
|
|
Copyright (c) 2006-2020, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file IFC.cpp
|
|
|
|
* @brief Implementation of the Industry Foundation Classes loader.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_IFCUTIL_H
|
|
|
|
#define INCLUDED_IFCUTIL_H
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#include "AssetLib/IFC/IFCLoader.h"
|
2021-01-13 21:43:46 +00:00
|
|
|
#include "AssetLib/IFC/IFCReaderGen_2x3.h"
|
2020-05-02 13:14:38 +00:00
|
|
|
#include "AssetLib/Step/STEPFile.h"
|
|
|
|
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/material.h>
|
2021-01-13 21:43:46 +00:00
|
|
|
#include <assimp/mesh.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
struct aiNode;
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
namespace IFC {
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
using IfcFloat = double;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
// IfcFloat-precision math data types
|
|
|
|
using IfcVector2 = aiVector2t<IfcFloat>;
|
|
|
|
using IfcVector3 = aiVector3t<IfcFloat>;
|
|
|
|
using IfcMatrix4 = aiMatrix4x4t<IfcFloat>;
|
|
|
|
using IfcMatrix3 = aiMatrix3x3t<IfcFloat>;
|
|
|
|
using IfcColor4 = aiColor4t<IfcFloat>;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Helper for std::for_each to delete all heap-allocated items in a container
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-13 21:43:46 +00:00
|
|
|
template <typename T>
|
2018-01-13 09:27:45 +00:00
|
|
|
struct delete_fun {
|
2021-01-13 21:43:46 +00:00
|
|
|
void operator()(T *del) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete del;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Helper used during mesh construction. Aids at creating aiMesh'es out of relatively few polygons.
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-01-13 09:27:45 +00:00
|
|
|
struct TempMesh {
|
|
|
|
std::vector<IfcVector3> mVerts;
|
|
|
|
std::vector<unsigned int> mVertcnt;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// utilities
|
2021-01-13 21:43:46 +00:00
|
|
|
aiMesh *ToMesh();
|
2015-05-19 03:57:13 +00:00
|
|
|
void Clear();
|
2021-01-13 21:43:46 +00:00
|
|
|
void Transform(const IfcMatrix4 &mat);
|
2015-05-19 03:57:13 +00:00
|
|
|
IfcVector3 Center() const;
|
2021-01-13 21:43:46 +00:00
|
|
|
void Append(const TempMesh &other);
|
2018-01-13 09:27:45 +00:00
|
|
|
bool IsEmpty() const;
|
2015-05-19 03:57:13 +00:00
|
|
|
void RemoveAdjacentDuplicates();
|
|
|
|
void RemoveDegenerates();
|
|
|
|
void FixupFaceOrientation();
|
2021-01-13 21:43:46 +00:00
|
|
|
static IfcVector3 ComputePolygonNormal(const IfcVector3 *vtcs, size_t cnt, bool normalize = true);
|
2015-05-19 03:57:13 +00:00
|
|
|
IfcVector3 ComputeLastPolygonNormal(bool normalize = true) const;
|
2021-01-13 21:43:46 +00:00
|
|
|
void ComputePolygonNormals(std::vector<IfcVector3> &normals, bool normalize = true, size_t ofs = 0) const;
|
|
|
|
void Swap(TempMesh &other);
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
inline bool TempMesh::IsEmpty() const {
|
2018-01-13 09:27:45 +00:00
|
|
|
return mVerts.empty() && mVertcnt.empty();
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Temporary representation of an opening in a wall or a floor
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-13 21:43:46 +00:00
|
|
|
struct TempOpening {
|
2018-01-13 09:27:45 +00:00
|
|
|
const IFC::Schema_2x3::IfcSolidModel *solid;
|
2015-05-19 03:57:13 +00:00
|
|
|
IfcVector3 extrusionDir;
|
|
|
|
|
2016-04-05 21:23:53 +00:00
|
|
|
std::shared_ptr<TempMesh> profileMesh;
|
|
|
|
std::shared_ptr<TempMesh> profileMesh2D;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// list of points generated for this opening. This is used to
|
|
|
|
// create connections between two opposing holes created
|
|
|
|
// from a single opening instance (two because walls tend to
|
|
|
|
// have two sides). If !empty(), the other side of the wall
|
|
|
|
// has already been processed.
|
|
|
|
std::vector<IfcVector3> wallPoints;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
2021-01-13 21:43:46 +00:00
|
|
|
TempOpening() :
|
|
|
|
solid(),
|
|
|
|
extrusionDir(),
|
|
|
|
profileMesh() {
|
|
|
|
// empty
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
2021-01-13 21:43:46 +00:00
|
|
|
TempOpening(const IFC::Schema_2x3::IfcSolidModel *solid, IfcVector3 extrusionDir,
|
|
|
|
std::shared_ptr<TempMesh> profileMesh,
|
|
|
|
std::shared_ptr<TempMesh> profileMesh2D) :
|
|
|
|
solid(solid),
|
|
|
|
extrusionDir(extrusionDir),
|
|
|
|
profileMesh(profileMesh),
|
|
|
|
profileMesh2D(profileMesh2D) {
|
|
|
|
// empty
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
2021-01-13 21:43:46 +00:00
|
|
|
void Transform(const IfcMatrix4 &mat); // defined later since TempMesh is not complete yet
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
// Helper to sort openings by distance from a given base point
|
|
|
|
struct DistanceSorter {
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
DistanceSorter(const IfcVector3 &base) :
|
|
|
|
base(base) {}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
bool operator()(const TempOpening &a, const TempOpening &b) const {
|
|
|
|
return (a.profileMesh->Center() - base).SquareLength() < (b.profileMesh->Center() - base).SquareLength();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IfcVector3 base;
|
|
|
|
};
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Intermediate data storage during conversion. Keeps everything and a bit more.
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-13 21:43:46 +00:00
|
|
|
struct ConversionData {
|
|
|
|
ConversionData(const STEP::DB &db, const IFC::Schema_2x3::IfcProject &proj, aiScene *out, const IFCImporter::Settings &settings) :
|
|
|
|
len_scale(1.0),
|
|
|
|
angle_scale(-1.0),
|
|
|
|
plane_angle_in_radians(true),
|
|
|
|
db(db),
|
|
|
|
proj(proj),
|
|
|
|
out(out),
|
|
|
|
wcs(),
|
|
|
|
meshes(),
|
|
|
|
materials(),
|
|
|
|
cached_meshes(),
|
|
|
|
cached_materials(),
|
|
|
|
settings(settings),
|
|
|
|
apply_openings(nullptr),
|
|
|
|
collect_openings(nullptr),
|
|
|
|
already_processed() {
|
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
~ConversionData() {
|
2021-01-13 21:43:46 +00:00
|
|
|
std::for_each(meshes.begin(), meshes.end(), delete_fun<aiMesh>());
|
|
|
|
std::for_each(materials.begin(), materials.end(), delete_fun<aiMaterial>());
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IfcFloat len_scale, angle_scale;
|
|
|
|
bool plane_angle_in_radians;
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
const STEP::DB &db;
|
|
|
|
const IFC::Schema_2x3::IfcProject &proj;
|
|
|
|
aiScene *out;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
IfcMatrix4 wcs;
|
2021-01-13 21:43:46 +00:00
|
|
|
std::vector<aiMesh *> meshes;
|
|
|
|
std::vector<aiMaterial *> materials;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
struct MeshCacheIndex {
|
2021-01-13 21:43:46 +00:00
|
|
|
const IFC::Schema_2x3::IfcRepresentationItem *item;
|
|
|
|
unsigned int matindex;
|
|
|
|
MeshCacheIndex() :
|
|
|
|
item(nullptr), matindex(0) {}
|
|
|
|
MeshCacheIndex(const IFC::Schema_2x3::IfcRepresentationItem *i, unsigned int mi) :
|
|
|
|
item(i), matindex(mi) {}
|
|
|
|
bool operator==(const MeshCacheIndex &o) const { return item == o.item && matindex == o.matindex; }
|
|
|
|
bool operator<(const MeshCacheIndex &o) const { return item < o.item || (item == o.item && matindex < o.matindex); }
|
2015-05-19 03:57:13 +00:00
|
|
|
};
|
2021-01-13 21:43:46 +00:00
|
|
|
using MeshCache = std::map<MeshCacheIndex, std::set<unsigned int>>;
|
2015-05-19 03:57:13 +00:00
|
|
|
MeshCache cached_meshes;
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
using MaterialCache = std::map<const IFC::Schema_2x3::IfcSurfaceStyle *, unsigned int>;
|
2015-05-19 03:57:13 +00:00
|
|
|
MaterialCache cached_materials;
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
const IFCImporter::Settings &settings;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Intermediate arrays used to resolve openings in walls: only one of them
|
|
|
|
// can be given at a time. apply_openings if present if the current element
|
|
|
|
// is a wall and needs its openings to be poured into its geometry while
|
|
|
|
// collect_openings is present only if the current element is an
|
|
|
|
// IfcOpeningElement, for which all the geometry needs to be preserved
|
|
|
|
// for later processing by a parent, which is a wall.
|
2021-01-13 21:43:46 +00:00
|
|
|
std::vector<TempOpening> *apply_openings;
|
|
|
|
std::vector<TempOpening> *collect_openings;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
std::set<uint64_t> already_processed;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Binary predicate to compare vectors with a given, quadratic epsilon.
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
struct FuzzyVectorCompare {
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
FuzzyVectorCompare(IfcFloat epsilon) :
|
|
|
|
epsilon(epsilon) {}
|
|
|
|
bool operator()(const IfcVector3 &a, const IfcVector3 &b) {
|
|
|
|
return std::abs((a - b).SquareLength()) < epsilon;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
const IfcFloat epsilon;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Ordering predicate to totally order R^2 vectors first by x and then by y
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
struct XYSorter {
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// sort first by X coordinates, then by Y coordinates
|
2021-01-13 21:43:46 +00:00
|
|
|
bool operator()(const IfcVector2 &a, const IfcVector2 &b) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (a.x == b.x) {
|
|
|
|
return a.y < b.y;
|
|
|
|
}
|
|
|
|
return a.x < b.x;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// conversion routines for common IFC entities, implemented in IFCUtil.cpp
|
2021-01-13 21:43:46 +00:00
|
|
|
void ConvertColor(aiColor4D &out, const Schema_2x3::IfcColourRgb &in);
|
|
|
|
void ConvertColor(aiColor4D &out, const Schema_2x3::IfcColourOrFactor &in, ConversionData &conv, const aiColor4D *base);
|
|
|
|
void ConvertCartesianPoint(IfcVector3 &out, const Schema_2x3::IfcCartesianPoint &in);
|
|
|
|
void ConvertDirection(IfcVector3 &out, const Schema_2x3::IfcDirection &in);
|
|
|
|
void ConvertVector(IfcVector3 &out, const Schema_2x3::IfcVector &in);
|
|
|
|
void AssignMatrixAxes(IfcMatrix4 &out, const IfcVector3 &x, const IfcVector3 &y, const IfcVector3 &z);
|
|
|
|
void ConvertAxisPlacement(IfcMatrix4 &out, const Schema_2x3::IfcAxis2Placement3D &in);
|
|
|
|
void ConvertAxisPlacement(IfcMatrix4 &out, const Schema_2x3::IfcAxis2Placement2D &in);
|
|
|
|
void ConvertAxisPlacement(IfcVector3 &axis, IfcVector3 &pos, const IFC::Schema_2x3::IfcAxis1Placement &in);
|
|
|
|
void ConvertAxisPlacement(IfcMatrix4 &out, const Schema_2x3::IfcAxis2Placement &in, ConversionData &conv);
|
|
|
|
void ConvertTransformOperator(IfcMatrix4 &out, const Schema_2x3::IfcCartesianTransformationOperator &op);
|
|
|
|
bool IsTrue(const Assimp::STEP::EXPRESS::BOOLEAN &in);
|
|
|
|
IfcFloat ConvertSIPrefix(const std::string &prefix);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// IFCProfile.cpp
|
2021-01-13 21:43:46 +00:00
|
|
|
bool ProcessProfile(const Schema_2x3::IfcProfileDef &prof, TempMesh &meshout, ConversionData &conv);
|
|
|
|
bool ProcessCurve(const Schema_2x3::IfcCurve &curve, TempMesh &meshout, ConversionData &conv);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// IFCMaterial.cpp
|
2021-01-13 21:43:46 +00:00
|
|
|
unsigned int ProcessMaterials(uint64_t id, unsigned int prevMatId, ConversionData &conv, bool forceDefaultMat);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// IFCGeometry.cpp
|
2021-01-13 21:43:46 +00:00
|
|
|
IfcMatrix3 DerivePlaneCoordinateSpace(const TempMesh &curmesh, bool &ok, IfcVector3 &norOut);
|
|
|
|
bool ProcessRepresentationItem(const Schema_2x3::IfcRepresentationItem &item, unsigned int matid, std::set<unsigned int> &mesh_indices, ConversionData &conv);
|
|
|
|
void AssignAddedMeshes(std::set<unsigned int> &mesh_indices, aiNode *nd, ConversionData & /*conv*/);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
void ProcessSweptAreaSolid(const Schema_2x3::IfcSweptAreaSolid &swept, TempMesh &meshout,
|
|
|
|
ConversionData &conv);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
void ProcessExtrudedAreaSolid(const Schema_2x3::IfcExtrudedAreaSolid &solid, TempMesh &result,
|
|
|
|
ConversionData &conv, bool collect_openings);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// IFCBoolean.cpp
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
void ProcessBoolean(const Schema_2x3::IfcBooleanResult &boolean, TempMesh &result, ConversionData &conv);
|
|
|
|
void ProcessBooleanHalfSpaceDifference(const Schema_2x3::IfcHalfSpaceSolid *hs, TempMesh &result,
|
|
|
|
const TempMesh &first_operand,
|
|
|
|
ConversionData &conv);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
void ProcessPolygonalBoundedBooleanHalfSpaceDifference(const Schema_2x3::IfcPolygonalBoundedHalfSpace *hs, TempMesh &result,
|
|
|
|
const TempMesh &first_operand,
|
|
|
|
ConversionData &conv);
|
|
|
|
void ProcessBooleanExtrudedAreaSolidDifference(const Schema_2x3::IfcExtrudedAreaSolid *as, TempMesh &result,
|
|
|
|
const TempMesh &first_operand,
|
|
|
|
ConversionData &conv);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// IFCOpenings.cpp
|
|
|
|
|
2021-01-13 21:43:46 +00:00
|
|
|
bool GenerateOpenings(std::vector<TempOpening> &openings,
|
|
|
|
const std::vector<IfcVector3> &nors,
|
|
|
|
TempMesh &curmesh,
|
|
|
|
bool check_intersection,
|
|
|
|
bool generate_connection_geometry,
|
|
|
|
const IfcVector3 &wall_extrusion_axis = IfcVector3(0, 1, 0));
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// IFCCurve.cpp
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Custom exception for use by members of the Curve class
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-01-13 09:27:45 +00:00
|
|
|
class CurveError {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2021-01-13 21:43:46 +00:00
|
|
|
CurveError(const std::string &s) :
|
|
|
|
mStr(s) {
|
2018-01-13 09:27:45 +00:00
|
|
|
// empty
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2018-01-13 09:27:45 +00:00
|
|
|
std::string mStr;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Temporary representation for an arbitrary sub-class of IfcCurve. Used to sample the curves
|
|
|
|
// to obtain a list of line segments.
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-01-13 09:27:45 +00:00
|
|
|
class Curve {
|
2015-05-19 03:48:29 +00:00
|
|
|
protected:
|
2021-01-13 21:43:46 +00:00
|
|
|
Curve(const Schema_2x3::IfcCurve &base_entity, ConversionData &conv) :
|
|
|
|
base_entity(base_entity),
|
|
|
|
conv(conv) {
|
2018-01-13 09:27:45 +00:00
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2021-01-13 21:43:46 +00:00
|
|
|
using ParamRange = std::pair<IfcFloat, IfcFloat>;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
virtual ~Curve() {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// check if a curve is closed
|
|
|
|
virtual bool IsClosed() const = 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// evaluate the curve at the given parametric position
|
|
|
|
virtual IfcVector3 Eval(IfcFloat p) const = 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// try to match a point on the curve to a given parameter
|
|
|
|
// for self-intersecting curves, the result is not ambiguous and
|
|
|
|
// it is undefined which parameter is returned.
|
2021-01-13 21:43:46 +00:00
|
|
|
virtual bool ReverseEval(const IfcVector3 &val, IfcFloat ¶mOut) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// get the range of the curve (both inclusive).
|
|
|
|
// +inf and -inf are valid return values, the curve is not bounded in such a case.
|
2021-01-13 21:43:46 +00:00
|
|
|
virtual std::pair<IfcFloat, IfcFloat> GetParametricRange() const = 0;
|
2015-05-19 03:57:13 +00:00
|
|
|
IfcFloat GetParametricRangeDelta() const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// estimate the number of sample points that this curve will require
|
2021-01-13 21:43:46 +00:00
|
|
|
virtual size_t EstimateSampleCount(IfcFloat start, IfcFloat end) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// intelligently sample the curve based on the current settings
|
|
|
|
// and append the result to the mesh
|
2021-01-13 21:43:46 +00:00
|
|
|
virtual void SampleDiscrete(TempMesh &out, IfcFloat start, IfcFloat end) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#ifdef ASSIMP_BUILD_DEBUG
|
2015-05-19 03:57:13 +00:00
|
|
|
// check if a particular parameter value lies within the well-defined range
|
|
|
|
bool InRange(IfcFloat) const;
|
2015-05-19 03:52:10 +00:00
|
|
|
#endif
|
2021-01-13 21:43:46 +00:00
|
|
|
static Curve *Convert(const IFC::Schema_2x3::IfcCurve &, ConversionData &conv);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
protected:
|
2021-01-13 21:43:46 +00:00
|
|
|
const Schema_2x3::IfcCurve &base_entity;
|
|
|
|
ConversionData &conv;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------
|
|
|
|
// A BoundedCurve always holds the invariant that GetParametricRange()
|
|
|
|
// never returns infinite values.
|
|
|
|
// --------------------------------------------------------------------------------
|
2018-01-13 09:27:45 +00:00
|
|
|
class BoundedCurve : public Curve {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2021-01-13 21:43:46 +00:00
|
|
|
BoundedCurve(const Schema_2x3::IfcBoundedCurve &entity, ConversionData &conv) :
|
|
|
|
Curve(entity, conv) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2021-01-13 21:43:46 +00:00
|
|
|
bool IsClosed() const override;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// sample the entire curve
|
2021-01-13 21:43:46 +00:00
|
|
|
void SampleDiscrete(TempMesh &out) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
using Curve::SampleDiscrete;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// IfcProfile.cpp
|
2021-01-13 21:43:46 +00:00
|
|
|
bool ProcessCurve(const Schema_2x3::IfcCurve &curve, TempMesh &meshout, ConversionData &conv);
|
|
|
|
|
|
|
|
} // namespace IFC
|
|
|
|
} // namespace Assimp
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
#endif
|