InternalParameters.FileCS =
(RWMesh_CoordinateSystem)(theResource->IntegerVal("file.cs", (int)InternalParameters.SystemCS, aScope) % 2);
- InternalParameters.WritePntSet =
- theResource->BooleanVal("write.pnt.set", InternalParameters.WritePntSet, aScope);
- InternalParameters.WriteDistance =
- theResource->RealVal("write.distance", InternalParameters.WriteDistance, aScope);
- InternalParameters.WriteDensity =
- theResource->RealVal("write.density", InternalParameters.WriteDensity, aScope);
- InternalParameters.WriteTolerance =
- theResource->RealVal("write.tolerance", InternalParameters.WriteTolerance, aScope);
InternalParameters.WriteNormals =
theResource->BooleanVal("write.normals", InternalParameters.WriteNormals, aScope);
InternalParameters.WriteColors =
aResult += "!Write parameters:\n";
aResult += "!\n";
- aResult += "!\n";
- aResult += "!Flag for write point cloud instead without triangulation indices\n";
- aResult += "!Default value: 0(false). Available values: 0(false), 1(true)\n";
- aResult += aScope + "write.pnt.set :\t " + InternalParameters.WritePntSet + "\n";
- aResult += "!\n";
-
- aResult += "!\n";
- aResult += "!Distance from shape into the range [0, Value]\n";
- aResult += "!Default value: 0. Available values: [0, Value]\n";
- aResult += aScope + "write.distance :\t " + InternalParameters.WriteDistance + "\n";
- aResult += "!\n";
-
- aResult += "!\n";
- aResult += "!Density of points to generate randomly on surface\n";
- aResult += "!Default value: 2.e+100. Available values: [0, inf]\n";
- aResult += aScope + "write.density :\t " + InternalParameters.WriteDensity + "\n";
- aResult += "!\n";
-
- aResult += "!\n";
- aResult += "!Internal tolerance\n";
- aResult += "!Default value: 1.e-7. Available values: [0, inf]\n";
- aResult += aScope + "write.tolerance :\t " + InternalParameters.WriteTolerance + "\n";
- aResult += "!\n";
-
aResult += "!\n";
aResult += "!Flag for write normals\n";
aResult += "!Default value: 1(true). Available values: 0(false), 1(true)\n";
#include <RWPly_Provider.hxx>
#include <BRep_Builder.hxx>
-#include <BRepLib_PointCloudShape.hxx>
#include <DE_Wrapper.hxx>
#include <Message.hxx>
#include <RWPly_ConfigurationNode.hxx>
return Standard_True;
}
- if (aNode->InternalParameters.WritePntSet)
+ TColStd_IndexedDataMapOfStringString aFileInfo;
+ if (!aNode->InternalParameters.WriteAuthor.IsEmpty())
{
- class PointCloudPlyWriter : public BRepLib_PointCloudShape, public RWPly_PlyWriterContext
- {
- public:
- PointCloudPlyWriter(Standard_Real theTol)
- : BRepLib_PointCloudShape(TopoDS_Shape(), theTol)
- {}
-
- void AddFaceColor(const TopoDS_Shape& theFace, const Graphic3d_Vec4ub& theColor)
- {
- myFaceColor.Bind(theFace, theColor);
- }
-
- protected:
- virtual void addPoint(const gp_Pnt& thePoint,
- const gp_Vec& theNorm,
- const gp_Pnt2d& theUV,
- const TopoDS_Shape& theFace)
- {
- Graphic3d_Vec4ub aColor;
- myFaceColor.Find(theFace, aColor);
- RWPly_PlyWriterContext::WriteVertex(thePoint,
- Graphic3d_Vec3((float)theNorm.X(), (float)theNorm.Y(), (float)theNorm.Z()),
- Graphic3d_Vec2((float)theUV.X(), (float)theUV.Y()),
- aColor);
- }
-
- private:
- NCollection_DataMap<TopoDS_Shape, Graphic3d_Vec4ub> myFaceColor;
- };
-
- PointCloudPlyWriter aPlyCtx(aNode->InternalParameters.WriteTolerance);
- aPlyCtx.SetNormals(aNode->InternalParameters.WriteNormals);
- aPlyCtx.SetColors(aNode->InternalParameters.WriteColors);
- aPlyCtx.SetTexCoords(aNode->InternalParameters.WriteTexCoords);
-
- TopoDS_Compound aComp;
- BRep_Builder().MakeCompound(aComp);
- for (XCAFPrs_DocumentExplorer aDocExplorer(theDocument, aRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
- aDocExplorer.More(); aDocExplorer.Next())
- {
- const XCAFPrs_DocumentNode& aDocNode = aDocExplorer.Current();
- for (RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, aDocNode.Location, true, aDocNode.Style); aFaceIter.More(); aFaceIter.Next())
- {
- BRep_Builder().Add(aComp, aFaceIter.Face());
- Graphic3d_Vec4ub aColorVec(255);
- if (aFaceIter.HasFaceColor())
- {
- Graphic3d_Vec4 aColorF = aFaceIter.FaceColor();
- aColorVec.SetValues((unsigned char)int(aColorF.r() * 255.0f),
- (unsigned char)int(aColorF.g() * 255.0f),
- (unsigned char)int(aColorF.b() * 255.0f),
- (unsigned char)int(aColorF.a() * 255.0f));
- }
- aPlyCtx.AddFaceColor(aFaceIter.Face(), aColorVec);
- }
- }
- aPlyCtx.SetShape(aComp);
- Standard_Integer aNbPoints = aNode->InternalParameters.WriteDensity > 0
- ? aPlyCtx.NbPointsByDensity(aNode->InternalParameters.WriteDensity)
- : aPlyCtx.NbPointsByTriangulation();
- if (aNbPoints <= 0)
- {
- Message::SendFail() << "Error in the RWPly_Provider during writing the file " <<
- thePath << "\t: Incorrect number of points";
- return false;
- }
-
- if (!aPlyCtx.Open(thePath)
- || !aPlyCtx.WriteHeader(aNbPoints, 0, TColStd_IndexedDataMapOfStringString()))
- {
- Message::SendFail() << "Error in the RWPly_Provider during writing the file " << thePath;
- return false;
- }
-
- Standard_Boolean isDone = aNode->InternalParameters.WriteDensity > 0
- ? aPlyCtx.GeneratePointsByDensity(aNode->InternalParameters.WriteDensity)
- : aPlyCtx.GeneratePointsByTriangulation();
- if (!isDone)
- {
- Message::SendFail() << "Error in the RWPly_Provider during writing the file "
- << thePath << "\t: Error during generating point process";
- return false;
- }
+ aFileInfo.Add("Author", aNode->InternalParameters.WriteAuthor);
}
- else
+ if (!aNode->InternalParameters.WriteComment.IsEmpty())
{
- TColStd_IndexedDataMapOfStringString aFileInfo;
- if (!aNode->InternalParameters.WriteAuthor.IsEmpty())
- {
- aFileInfo.Add("Author", aNode->InternalParameters.WriteAuthor);
- }
- if (!aNode->InternalParameters.WriteComment.IsEmpty())
- {
- aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment);
- }
- RWMesh_CoordinateSystemConverter aConverter;
- aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
- aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
- aConverter.SetOutputLengthUnit(aNode->InternalParameters.FileLengthUnit);
- aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
-
- RWPly_CafWriter aPlyCtx(thePath);
- aPlyCtx.SetNormals(aNode->InternalParameters.WriteNormals);
- aPlyCtx.SetColors(aNode->InternalParameters.WriteColors);
- aPlyCtx.SetTexCoords(aNode->InternalParameters.WriteTexCoords);
- aPlyCtx.SetPartId(aNode->InternalParameters.WritePartId);
- aPlyCtx.SetFaceId(aNode->InternalParameters.WriteFaceId);
- if (!aPlyCtx.Perform(theDocument, aFileInfo, theProgress))
- {
- Message::SendFail() << "Error in the RWPly_Provider during writing the file "
- << thePath << "\t: Cannot perform the document";
- return false;
- }
+ aFileInfo.Add("Comments", aNode->InternalParameters.WriteComment);
+ }
+ RWMesh_CoordinateSystemConverter aConverter;
+ aConverter.SetInputLengthUnit(aNode->GlobalParameters.LengthUnit / 1000);
+ aConverter.SetInputCoordinateSystem(aNode->InternalParameters.SystemCS);
+ aConverter.SetOutputLengthUnit(aNode->InternalParameters.FileLengthUnit);
+ aConverter.SetOutputCoordinateSystem(aNode->InternalParameters.FileCS);
+
+ RWPly_CafWriter aPlyCtx(thePath);
+ aPlyCtx.SetNormals(aNode->InternalParameters.WriteNormals);
+ aPlyCtx.SetColors(aNode->InternalParameters.WriteColors);
+ aPlyCtx.SetTexCoords(aNode->InternalParameters.WriteTexCoords);
+ aPlyCtx.SetPartId(aNode->InternalParameters.WritePartId);
+ aPlyCtx.SetFaceId(aNode->InternalParameters.WriteFaceId);
+ if (!aPlyCtx.Perform(theDocument, aFileInfo, theProgress))
+ {
+ Message::SendFail() << "Error in the RWPly_Provider during writing the file "
+ << thePath << "\t: Cannot perform the document";
+ return false;
}
+
return true;
}