Thu, 11/05/2020 - 12:34
Forums:
Hi,
I would like to load a step with color and display it in the context. But I don't know how to put them in the context.
I Use STEPCAFControl_Reader in order to read the color in the inputted step but nothing appear :
STEPCAFControl_Reader caf_reader;
caf_reader.SetColorMode (true);
caf_reader.SetMatMode (true);
IFSelect_ReturnStatus error = caf_reader.ReadFile (i_filename.c_str());
STEPControl_Reader reader = caf_reader.Reader();
if (error == IFSelect_RetDone)
{
reader.NbRootsForTransfer();
reader.TransferRoots();
reader.GiveList ("step-faces");
auto a = reader.NbShapes();
o_shape = reader.OneShape();
Handle_AIS_InteractiveObject m_aisObject = new AIS_Shape (o_shape );
m_aisObject->SetDisplayMode (AIS_Shaded);
m_aisObject->SetHilightMode (AIS_Shaded);
m_aisObject->Attributes()->SetFaceBoundaryDraw (Standard_True);
m_aisObject->Attributes()->SetIsoOnTriangulation (Standard_True);
m_aisContext->Display (m_aisObject, true);
}
Is anyone know what is wrong in this code ? Thanks in advance.
Regards,
Manon
Mon, 11/09/2020 - 14:39
AIS_Shape displays just a TopoDS_Shape with a single color.
To see colors from STEP file you need either using XCAFPrs_AISObject instead of AIS_Shape, or do color dispatching logic from XCAF document on your own.
For using XCAFPrs_AISObject presentation, STEPCAFControl_Reader::Transfer() should be called to fill in an XCAF document, as STEPControl_Reader::OneShape() in your code snippet just returns a shape without any attributes (names, colors, PMI, etc.).
Sun, 10/03/2021 - 13:09
HI Kirill,
can you please post snippet of code which ale to read step file using STEPCAFControl_Reader and show the color..
This is my code
#include <iostream>
#include <STEPControl_Reader.hxx>
#include <string>
#include <TopTools_HSequenceOfShape.hxx>
/////////////////////////////////////////
#include <AIS_ViewCube.hxx>
#include <AIS_Shape.hxx>
#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Line.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <IFSelect_ReturnStatus.hxx>
#include <IGESControl_Controller.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESControl_Writer.hxx>
#include <Interface_Static.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>
#include <StlAPI_Writer.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <VrmlAPI_Writer.hxx>
#include <V3d_Viewer.hxx>
/////////////////////////////////////////
#include <IVtkTools_ShapeDataSource.hxx>
#include <vtkAutoInit.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <STEPCAFControl_Reader.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <TDataStd_Name.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
int main()
{
STEPCAFControl_Reader reader;
IFSelect_ReturnStatus stat = reader.ReadFile("F:\\Pallaavi\\OpenCascade\\Practice\\opencascade\\Assem1.STEP");
Handle(TDocStd_Document) aDoc;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();
anApp->NewDocument("MDTV-XCAF", aDoc);
if (!reader.Transfer(aDoc))
{
std::cout << "Cannot read any relevant data from the STEP file" << endl;
// abandon ..
}
Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
TDF_LabelSequence labelSequence;
myAssembly->GetShapes(labelSequence);
for (int i = 1; i <= labelSequence.Length(); i++)
{
const TDF_Label& label = labelSequence.Value(i);
TopoDS_Shape S = myAssembly->GetShape(label);
Handle(TDataStd_Name) name;
if (label.FindAttribute(TDataStd_Name::GetID(), name))
{
TCollection_ExtendedString extstr = name->Get();
}
}
vtkNew<vtkRenderWindow> renewin;
vtkNew<vtkRenderer> ren;
renewin->AddRenderer(ren);
vtkNew<vtkInteractorStyleTrackballCamera> istyle;
vtkNew<vtkRenderWindowInteractor> iren;
//
iren->SetRenderWindow(renewin);
iren->SetInteractorStyle(istyle);
//Domain data (TopoDS_Shape) -> vtkPolyData -> mapper -> actor
vtkNew<IVtkTools_ShapeDataSource> occSource;
occSource->SetShape(new IVtkOCC_Shape(S));
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(occSource->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
ren->AddActor(actor);
renewin->Render();
iren->Start();
return 0;
}
Sun, 10/03/2021 - 14:25
AIS provides XCAFPrs_AISObject interactive object for mapping colors from XCAF document. IVtkTools_ShapeDataSource, however, has no bindings to XCAF. So that if you want using VTK, you'll have to implement color dispatching on your own - with help of XCAFPrs::CollectStyleSettings() for example.