mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-04 18:06:22 +03:00
0031544: Visualization - show boundaries of faces in shading mode of VTK presentation
This commit is contained in:
parent
158f2931a7
commit
4db6748cc5
@ -718,6 +718,93 @@ static Standard_Integer VtkSetDisplayMode (Draw_Interpretor& theDI,
|
||||
return 0;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : VtkSetBoundaryDraw
|
||||
// Purpose :
|
||||
// Draw args : ivtksetboundingdraw [name] draw on/off(0,1)
|
||||
//================================================================
|
||||
static Standard_Integer VtkSetBoundaryDraw(Draw_Interpretor& theDI,
|
||||
Standard_Integer theArgNum,
|
||||
const char** theArgs)
|
||||
{
|
||||
// Check viewer
|
||||
if (!GetInteractor()->IsEnabled())
|
||||
{
|
||||
theDI << theArgs[0] << " error: call ivtkinit before\n";
|
||||
return 1; // TCL_ERROR
|
||||
}
|
||||
|
||||
// Check arguments
|
||||
if (theArgNum != 2 && theArgNum != 3)
|
||||
{
|
||||
theDI << theArgs[0] << " error: expects 1 or 2 arguments\n";
|
||||
return 1; // TCL_ERROR
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkActor> anActor;
|
||||
// Set disp mode for all objects
|
||||
if (theArgNum == 2)
|
||||
{
|
||||
// Get mode
|
||||
Standard_Integer toDraw = Draw::Atoi(theArgs[1]);
|
||||
DoubleMapOfActorsAndNames::Iterator anIter(GetMapOfActors());
|
||||
while (anIter.More())
|
||||
{
|
||||
anActor = anIter.Key1();
|
||||
// Set Red color for boundary edges
|
||||
vtkLookupTable* aTable = (vtkLookupTable*)anActor->GetMapper()->GetLookupTable();
|
||||
IVtkTools::SetLookupTableColor(aTable, MT_SharedEdge, 1., 0., 0., 1.);
|
||||
|
||||
IVtkTools_ShapeDataSource* aSrc = IVtkTools_ShapeObject::GetShapeSource(anActor);
|
||||
if (aSrc)
|
||||
{
|
||||
IVtkOCC_Shape::Handle anOccShape = aSrc->GetShape();
|
||||
if (!anOccShape.IsNull())
|
||||
{
|
||||
IVtkTools_DisplayModeFilter* aFilter = GetPipeline(anOccShape->GetId())->GetDisplayModeFilter();
|
||||
aFilter->SetDisplayMode(DM_Shading);
|
||||
aFilter->SetFaceBoundaryDraw(toDraw != 0);
|
||||
aFilter->Modified();
|
||||
aFilter->Update();
|
||||
}
|
||||
}
|
||||
anIter.Next();
|
||||
}
|
||||
}
|
||||
// Set disp mode for named object
|
||||
else
|
||||
{
|
||||
Standard_Integer toDraw = Draw::Atoi(theArgs[2]);
|
||||
TCollection_AsciiString aName = theArgs[1];
|
||||
if (GetMapOfActors().IsBound2(aName))
|
||||
{
|
||||
anActor = GetMapOfActors().Find2(aName);
|
||||
// Set Red color for boundary edges
|
||||
vtkLookupTable* aTable = (vtkLookupTable*)anActor->GetMapper()->GetLookupTable();
|
||||
IVtkTools::SetLookupTableColor(aTable, MT_SharedEdge, 1., 0., 0., 1.);
|
||||
|
||||
vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc = IVtkTools_ShapeObject::GetShapeSource(anActor);
|
||||
if (aSrc)
|
||||
{
|
||||
IVtkOCC_Shape::Handle anOccShape = aSrc->GetShape();
|
||||
if (!anOccShape.IsNull())
|
||||
{
|
||||
IVtkTools_DisplayModeFilter* aFilter = GetPipeline(anOccShape->GetId())->GetDisplayModeFilter();
|
||||
aFilter->SetDisplayMode(DM_Shading);
|
||||
aFilter->SetFaceBoundaryDraw(toDraw != 0);
|
||||
aFilter->Modified();
|
||||
aFilter->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redraw window
|
||||
GetInteractor()->Render();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//================================================================
|
||||
// Function : VtkSetSelectionMode
|
||||
// Purpose :
|
||||
@ -1197,6 +1284,13 @@ void IVtkDraw::Commands (Draw_Interpretor& theCommands)
|
||||
"if name is not defined.",
|
||||
__FILE__, VtkSetDisplayMode, group);
|
||||
|
||||
theCommands.Add("ivtksetboundingdraw",
|
||||
"ivtksetboundingdraw usage:\n"
|
||||
"ivtksetboundingdraw [name] draw on/off (0,1)"
|
||||
"\n\t\t: Sets or unsets boundaries drawing for shading display mode to the object with name 'name' or to all objects"
|
||||
"if name is not defined.",
|
||||
__FILE__, VtkSetBoundaryDraw, group);
|
||||
|
||||
theCommands.Add("ivtksetselmode",
|
||||
"ivtksetselmode usage:\n"
|
||||
" ivtksetselmode [name] mode on/off(0,1)"
|
||||
|
@ -35,7 +35,8 @@ vtkStandardNewMacro(IVtkTools_DisplayModeFilter)
|
||||
//============================================================================
|
||||
IVtkTools_DisplayModeFilter::IVtkTools_DisplayModeFilter()
|
||||
: myDisplayMode (DM_Wireframe),
|
||||
myDoDisplaySharedVertices (false)
|
||||
myDoDisplaySharedVertices (false),
|
||||
myDrawFaceBoundaries( false )
|
||||
{
|
||||
// Filter according to values in subshapes types array.
|
||||
myIdsArrayName = IVtkVTK_ShapeData::ARRNAME_MESH_TYPES();
|
||||
@ -49,20 +50,22 @@ IVtkTools_DisplayModeFilter::IVtkTools_DisplayModeFilter()
|
||||
aTypes.Add (MT_SharedEdge);
|
||||
aTypes.Add (MT_WireFrameFace);
|
||||
|
||||
myModesDefinition.Bind (DM_Wireframe, aTypes);
|
||||
myModesDefinition[DM_Wireframe] = aTypes;
|
||||
|
||||
aTypes.Clear();
|
||||
aTypes.Add (MT_FreeVertex);
|
||||
aTypes.Add (MT_ShadedFace);
|
||||
|
||||
myModesDefinition.Bind (DM_Shading, aTypes);
|
||||
myModesDefinition[DM_Shading] = aTypes;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: Destructor
|
||||
// Purpose:
|
||||
//============================================================================
|
||||
IVtkTools_DisplayModeFilter::~IVtkTools_DisplayModeFilter() { }
|
||||
IVtkTools_DisplayModeFilter::~IVtkTools_DisplayModeFilter()
|
||||
{
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: RequestData
|
||||
@ -73,7 +76,7 @@ int IVtkTools_DisplayModeFilter::RequestData (vtkInformation *theRequest,
|
||||
vtkInformationVector **theInputVector,
|
||||
vtkInformationVector *theOutputVector)
|
||||
{
|
||||
SetData (myModesDefinition.Find (myDisplayMode));
|
||||
SetData (myModesDefinition[myDisplayMode]);
|
||||
return Superclass::RequestData (theRequest, theInputVector, theOutputVector);
|
||||
}
|
||||
|
||||
@ -104,24 +107,20 @@ void IVtkTools_DisplayModeFilter::SetDisplaySharedVertices (const bool theDoDisp
|
||||
if (myDoDisplaySharedVertices != theDoDisplay)
|
||||
{
|
||||
myDoDisplaySharedVertices = theDoDisplay;
|
||||
vtkIdType aVertexType = MT_SharedVertex;
|
||||
NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap>::Iterator aModes (myModesDefinition);
|
||||
NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap> aNewModes;
|
||||
IVtk_IdTypeMap aModeTypes;
|
||||
for (; aModes.More(); aModes.Next())
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
aModeTypes = aModes.Value();
|
||||
if (theDoDisplay && !aModeTypes.Contains(aVertexType))
|
||||
aModeTypes = myModesDefinition[i];
|
||||
if (theDoDisplay && !aModeTypes.Contains(MT_SharedVertex))
|
||||
{
|
||||
aModeTypes.Add (aVertexType);
|
||||
aModeTypes.Add (MT_SharedVertex);
|
||||
}
|
||||
else if (!theDoDisplay && aModeTypes.Contains (aVertexType))
|
||||
else if (!theDoDisplay && aModeTypes.Contains (MT_SharedVertex))
|
||||
{
|
||||
aModeTypes.Remove (aVertexType);
|
||||
aModeTypes.Remove (MT_SharedVertex);
|
||||
}
|
||||
aNewModes.Bind (aModes.Key(), aModeTypes);
|
||||
myModesDefinition[i] = aModeTypes;
|
||||
}
|
||||
myModesDefinition = aNewModes;
|
||||
Modified();
|
||||
}
|
||||
}
|
||||
@ -148,3 +147,39 @@ IVtk_DisplayMode IVtkTools_DisplayModeFilter::GetDisplayMode () const
|
||||
return myDisplayMode;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: meshTypesForMode
|
||||
// Purpose:
|
||||
//============================================================================
|
||||
const IVtk_IdTypeMap& IVtkTools_DisplayModeFilter::MeshTypesForMode(IVtk_DisplayMode theMode) const
|
||||
{
|
||||
return myModesDefinition[theMode];
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: setMeshTypesForMode
|
||||
// Purpose:
|
||||
//============================================================================
|
||||
void IVtkTools_DisplayModeFilter::SetMeshTypesForMode(IVtk_DisplayMode theMode, const IVtk_IdTypeMap& theMeshTypes)
|
||||
{
|
||||
myModesDefinition[theMode] = theMeshTypes;
|
||||
Modified();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: SetFaceBoundaryDraw
|
||||
// Purpose:
|
||||
//============================================================================
|
||||
void IVtkTools_DisplayModeFilter::SetFaceBoundaryDraw(bool theToDraw)
|
||||
{
|
||||
myDrawFaceBoundaries = theToDraw;
|
||||
if (theToDraw) {
|
||||
myModesDefinition[DM_Shading].Add(MT_BoundaryEdge);
|
||||
myModesDefinition[DM_Shading].Add(MT_SharedEdge);
|
||||
}
|
||||
else {
|
||||
myModesDefinition[DM_Shading].Remove(MT_BoundaryEdge);
|
||||
myModesDefinition[DM_Shading].Remove(MT_SharedEdge);
|
||||
}
|
||||
Modified();
|
||||
}
|
||||
|
@ -46,6 +46,18 @@ public:
|
||||
//! Get current display mode.
|
||||
IVtk_DisplayMode GetDisplayMode() const;
|
||||
|
||||
//! Returns list of displaying mesh element types for the given display mode
|
||||
const IVtk_IdTypeMap& MeshTypesForMode(IVtk_DisplayMode theMode) const;
|
||||
|
||||
//! Set a list of displaying mesh element types for the given display mode
|
||||
void SetMeshTypesForMode(IVtk_DisplayMode theMode, const IVtk_IdTypeMap& theMeshTypes);
|
||||
|
||||
//! Draw Boundary of faces for shading mode
|
||||
void SetFaceBoundaryDraw(bool theToDraw);
|
||||
|
||||
//! Returns True if drawing Boundary of faces for shading mode is defined.
|
||||
bool FaceBoundaryDraw() const { return myDrawFaceBoundaries; }
|
||||
|
||||
protected:
|
||||
//! Filter cells according to the given set of ids.
|
||||
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *);
|
||||
@ -55,9 +67,12 @@ protected:
|
||||
|
||||
protected:
|
||||
//! Display mode defining mesh types to pass through this filter.
|
||||
IVtk_DisplayMode myDisplayMode;
|
||||
NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap> myModesDefinition;
|
||||
bool myDoDisplaySharedVertices;
|
||||
IVtk_DisplayMode myDisplayMode;
|
||||
IVtk_IdTypeMap myModesDefinition[2];
|
||||
bool myDoDisplaySharedVertices;
|
||||
|
||||
//! Draw Face boundaries flag is applicable only for shading display mode.
|
||||
bool myDrawFaceBoundaries;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
20
tests/v3d/ivtk/boundary_draw
Normal file
20
tests/v3d/ivtk/boundary_draw
Normal file
@ -0,0 +1,20 @@
|
||||
puts "============="
|
||||
puts "boundary_draw"
|
||||
puts "============="
|
||||
puts ""
|
||||
#######################################################
|
||||
# Tests boundary draw changing in the IVtk view
|
||||
#######################################################
|
||||
|
||||
set anImage1 $imagedir/${casename}_1.png
|
||||
set anImage2 $imagedir/${casename}_2.png
|
||||
|
||||
ivtkinit
|
||||
box b 1 1 1
|
||||
ivtkdisplay b
|
||||
ivtksetdispmode 1
|
||||
ivtksetboundingdraw 1
|
||||
ivtkdump $anImage1
|
||||
|
||||
ivtksetboundingdraw 0
|
||||
ivtkdump $anImage2
|
Loading…
x
Reference in New Issue
Block a user