Skip to content

Commit

Permalink
Define the measurement unit of the output kovacsv#32
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Jul 16, 2023
1 parent 4b771bc commit 21e7fdd
Show file tree
Hide file tree
Showing 19 changed files with 1,670 additions and 185 deletions.
2 changes: 1 addition & 1 deletion dist/occt-import-js.js

Large diffs are not rendered by default.

Binary file modified dist/occt-import-js.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions occt-import-js/example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ int main (int argc, const char* argv[])
return 1;
}

TriangulationParams params;
ImportParams params;
Importer::Result result = importer->LoadFile (argv[1], params);
if (result != Importer::Result::Success) {
return 1;
}

//ObjWriter writer;
//WriteNode (importer->GetRootNode (), writer);
ObjWriter writer;
WriteNode (importer->GetRootNode (), writer);

DumpNode (importer->GetRootNode (), 0);

Expand Down
230 changes: 115 additions & 115 deletions occt-import-js/src/importer-brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,149 +10,149 @@
class BrepShapeMesh : public Mesh
{
public:
BrepShapeMesh (const TopoDS_Shape& shape) :
Mesh (),
shape (shape)
{

}

virtual std::string GetName () const override
{
return std::string ();
}

virtual bool GetColor (Color&) const override
{
return false;
}

virtual void EnumerateFaces (const std::function<void (const Face&)>& onFace) const override
{
for (TopExp_Explorer ex (shape, TopAbs_FACE); ex.More (); ex.Next ()) {
const TopoDS_Face& face = TopoDS::Face (ex.Current ());
OcctFace outputFace (face);
onFace (outputFace);
}
}
BrepShapeMesh (const TopoDS_Shape& shape) :
Mesh (),
shape (shape)
{

}

virtual std::string GetName () const override
{
return std::string ();
}

virtual bool GetColor (Color&) const override
{
return false;
}

virtual void EnumerateFaces (const std::function<void (const Face&)>& onFace) const override
{
for (TopExp_Explorer ex (shape, TopAbs_FACE); ex.More (); ex.Next ()) {
const TopoDS_Face& face = TopoDS::Face (ex.Current ());
OcctFace outputFace (face);
onFace (outputFace);
}
}

private:
const TopoDS_Shape& shape;
const TopoDS_Shape& shape;
};

class BrepStandaloneFacesMesh : public Mesh
{
public:
BrepStandaloneFacesMesh (const TopoDS_Shape& shape) :
Mesh (),
shape (shape)
{

}

bool HasFaces () const
{
TopExp_Explorer ex (shape, TopAbs_FACE, TopAbs_SHELL);
return ex.More ();
}

virtual std::string GetName () const override
{
return std::string ();
}

virtual bool GetColor (Color&) const override
{
return false;
}

virtual void EnumerateFaces (const std::function<void (const Face& face)>& onFace) const override
{
for (TopExp_Explorer ex (shape, TopAbs_FACE, TopAbs_SHELL); ex.More (); ex.Next ()) {
const TopoDS_Face& face = TopoDS::Face (ex.Current ());
OcctFace outputFace (face);
onFace (outputFace);
}
}
BrepStandaloneFacesMesh (const TopoDS_Shape& shape) :
Mesh (),
shape (shape)
{

}

bool HasFaces () const
{
TopExp_Explorer ex (shape, TopAbs_FACE, TopAbs_SHELL);
return ex.More ();
}

virtual std::string GetName () const override
{
return std::string ();
}

virtual bool GetColor (Color&) const override
{
return false;
}

virtual void EnumerateFaces (const std::function<void (const Face& face)>& onFace) const override
{
for (TopExp_Explorer ex (shape, TopAbs_FACE, TopAbs_SHELL); ex.More (); ex.Next ()) {
const TopoDS_Face& face = TopoDS::Face (ex.Current ());
OcctFace outputFace (face);
onFace (outputFace);
}
}

private:
const TopoDS_Shape& shape;
const TopoDS_Shape& shape;
};

class BrepNode : public Node
{
public:
BrepNode (const TopoDS_Shape& shape) :
shape (shape)
{

}

virtual std::string GetName () const override
{
return std::string ();
}

virtual std::vector<NodePtr> GetChildren () const override
{
return {};
}

virtual bool IsMeshNode () const override
{
return true;
}

virtual void EnumerateMeshes (const std::function<void (const Mesh&)>& onMesh) const override
{
// Enumerate solids
for (TopExp_Explorer ex (shape, TopAbs_SOLID); ex.More (); ex.Next ()) {
const TopoDS_Shape& currentShape = ex.Current ();
BrepShapeMesh outputShapeMesh (currentShape);
onMesh (outputShapeMesh);
}

// Enumerate shells that are not part of a solid
for (TopExp_Explorer ex (shape, TopAbs_SHELL, TopAbs_SOLID); ex.More (); ex.Next ()) {
const TopoDS_Shape& currentShape = ex.Current ();
BrepShapeMesh outputShapeMesh (currentShape);
onMesh (outputShapeMesh);
}

// Create a mesh from faces that are not part of a shell
BrepStandaloneFacesMesh standaloneFacesMesh (shape);
if (standaloneFacesMesh.HasFaces ()) {
onMesh (standaloneFacesMesh);
}
}
BrepNode (const TopoDS_Shape& shape) :
shape (shape)
{

}

virtual std::string GetName () const override
{
return std::string ();
}

virtual std::vector<NodePtr> GetChildren () const override
{
return {};
}

virtual bool IsMeshNode () const override
{
return true;
}

virtual void EnumerateMeshes (const std::function<void (const Mesh&)>& onMesh) const override
{
// Enumerate solids
for (TopExp_Explorer ex (shape, TopAbs_SOLID); ex.More (); ex.Next ()) {
const TopoDS_Shape& currentShape = ex.Current ();
BrepShapeMesh outputShapeMesh (currentShape);
onMesh (outputShapeMesh);
}

// Enumerate shells that are not part of a solid
for (TopExp_Explorer ex (shape, TopAbs_SHELL, TopAbs_SOLID); ex.More (); ex.Next ()) {
const TopoDS_Shape& currentShape = ex.Current ();
BrepShapeMesh outputShapeMesh (currentShape);
onMesh (outputShapeMesh);
}

// Create a mesh from faces that are not part of a shell
BrepStandaloneFacesMesh standaloneFacesMesh (shape);
if (standaloneFacesMesh.HasFaces ()) {
onMesh (standaloneFacesMesh);
}
}

private:
const TopoDS_Shape& shape;
const TopoDS_Shape& shape;
};

ImporterBrep::ImporterBrep () :
Importer (),
shape ()
Importer (),
shape ()
{

}

Importer::Result ImporterBrep::LoadFile (const std::vector<std::uint8_t>& fileContent, const TriangulationParams& params)
Importer::Result ImporterBrep::LoadFile (const std::vector<std::uint8_t>& fileContent, const ImportParams& params)
{
VectorBuffer inputBuffer (fileContent);
std::istream inputStream (&inputBuffer);
VectorBuffer inputBuffer (fileContent);
std::istream inputStream (&inputBuffer);

BRep_Builder builder;
BRepTools::Read (shape, inputStream, builder);
if (shape.IsNull ()) {
return Importer::Result::ImportFailed;
}
BRep_Builder builder;
BRepTools::Read (shape, inputStream, builder);
if (shape.IsNull ()) {
return Importer::Result::ImportFailed;
}

TriangulateShape (shape, params);
return Importer::Result::Success;
TriangulateShape (shape, params);
return Importer::Result::Success;
}

NodePtr ImporterBrep::GetRootNode () const
{
return std::make_shared<BrepNode> (shape);
return std::make_shared<BrepNode> (shape);
}
8 changes: 4 additions & 4 deletions occt-import-js/src/importer-brep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class ImporterBrep : public Importer
{
public:
ImporterBrep ();
ImporterBrep ();

virtual Result LoadFile (const std::vector<std::uint8_t>& fileContent, const TriangulationParams& params) override;
virtual NodePtr GetRootNode () const override;
virtual Result LoadFile (const std::vector<std::uint8_t>& fileContent, const ImportParams& params) override;
virtual NodePtr GetRootNode () const override;

private:
TopoDS_Shape shape;
TopoDS_Shape shape;
};
1 change: 0 additions & 1 deletion occt-import-js/src/importer-iges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ bool ImporterIges::TransferToDocument (const std::vector<std::uint8_t>& fileCont
return false;
}

document = new TDocStd_Document ("XmlXCAF");
if (!igesCafReader.Transfer (document)) {
std::remove (dummyFileName.c_str ());
return false;
Expand Down
1 change: 0 additions & 1 deletion occt-import-js/src/importer-step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ bool ImporterStep::TransferToDocument (const std::vector<std::uint8_t>& fileCont
return false;
}

document = new TDocStd_Document ("XmlXCAF");
if (!stepCafReader.Transfer (document)) {
return false;
}
Expand Down
9 changes: 4 additions & 5 deletions occt-import-js/src/importer-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ bool OcctFace::HasTriangulation () const
return true;
}

bool TriangulateShape (TopoDS_Shape& shape, const TriangulationParams& params)
bool TriangulateShape (TopoDS_Shape& shape, const ImportParams& params)
{
Standard_Real linDeflection = params.linearDeflection;
Standard_Real angDeflection = params.angularDeflection;

if (params.automatic) {
if (params.linearDeflectionType == ImportParams::LinearDeflectionType::BoundingBoxRatio) {
Bnd_Box boundingBox;
BRepBndLib::Add (shape, boundingBox, false);
if (boundingBox.IsVoid ()) {
Expand All @@ -110,11 +110,10 @@ bool TriangulateShape (TopoDS_Shape& shape, const TriangulationParams& params)
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
boundingBox.Get (xMin, yMin, zMin, xMax, yMax, zMax);
Standard_Real avgSize = ((xMax - xMin) + (yMax - yMin) + (zMax - zMin)) / 3.0;
linDeflection = avgSize / 1000.0;
linDeflection = avgSize * params.linearDeflection;
if (linDeflection < Precision::Confusion ()) {
linDeflection = 1.0;
linDeflection = 0.1;
}
angDeflection = 0.5;
}

BRepMesh_IncrementalMesh mesh (shape, linDeflection, Standard_False, angDeflection);
Expand Down
24 changes: 12 additions & 12 deletions occt-import-js/src/importer-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
class VectorBuffer : public std::streambuf
{
public:
VectorBuffer (const std::vector<uint8_t>& v);
VectorBuffer (const std::vector<uint8_t>& v);
};

class OcctFace : public Face
{
public:
OcctFace (const TopoDS_Face& face);
OcctFace (const TopoDS_Face& face);

virtual bool HasNormals () const override;
virtual bool GetColor (Color& color) const override;
virtual bool HasNormals () const override;
virtual bool GetColor (Color& color) const override;

virtual void EnumerateVertices (const std::function<void (double, double, double)>& onVertex) const override;
virtual void EnumerateNormals (const std::function<void (double, double, double)>& onNormal) const override;
virtual void EnumerateTriangles (const std::function<void (int, int, int)>& onTriangle) const override;
virtual void EnumerateVertices (const std::function<void (double, double, double)>& onVertex) const override;
virtual void EnumerateNormals (const std::function<void (double, double, double)>& onNormal) const override;
virtual void EnumerateTriangles (const std::function<void (int, int, int)>& onTriangle) const override;

protected:
bool HasTriangulation () const;
bool HasTriangulation () const;

const TopoDS_Face& face;
Handle (Poly_Triangulation) triangulation;
TopLoc_Location location;
const TopoDS_Face& face;
Handle (Poly_Triangulation) triangulation;
TopLoc_Location location;
};

bool TriangulateShape (TopoDS_Shape& shape, const TriangulationParams& params);
bool TriangulateShape (TopoDS_Shape& shape, const ImportParams& params);
Loading

0 comments on commit 21e7fdd

Please sign in to comment.