1 // Created on: 2011-10-14
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IVtkVTK_ShapeData.hxx>
17 #include <vtkCellArray.h>
18 #include <vtkCellData.h>
19 #include <vtkDoubleArray.h>
20 #include <vtkIdTypeArray.h>
21 #include <vtkPoints.h>
22 #include <vtkPolyData.h>
24 IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData,IVtk_IShapeData)
26 const char* const IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS = "SUBSHAPE_IDS";
28 const char* const IVtkVTK_ShapeData::ARRNAME_MESH_TYPES = "MESH_TYPES";
30 //! Handle implementation
33 //================================================================
34 // Function : Constructor
36 //================================================================
37 IVtkVTK_ShapeData::IVtkVTK_ShapeData()
39 myPolyData = vtkSmartPointer<vtkPolyData>::New();
40 myPolyData->Allocate();
41 myPolyData->SetPoints (vtkPoints::New());
43 mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New();
44 mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
45 mySubShapeIDs->SetNumberOfComponents (1);
46 myPolyData->GetCellData()->AddArray (mySubShapeIDs);
48 myMeshTypes = vtkSmartPointer<vtkIdTypeArray>::New();
49 myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES);
50 myMeshTypes->SetNumberOfComponents (1);
51 myPolyData->GetCellData()->AddArray (myMeshTypes);
54 //================================================================
55 // Function : Destructor
57 //================================================================
58 IVtkVTK_ShapeData::~IVtkVTK_ShapeData()
61 //================================================================
62 // Function : InsertCoordinate
64 //================================================================
65 IVtk_PointId IVtkVTK_ShapeData::InsertCoordinate (double theX,
69 return myPolyData->GetPoints()->InsertNextPoint (theX, theY, theZ);
72 //================================================================
73 // Function : InsertVertex
75 //================================================================
76 void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID,
77 const IVtk_PointId thePointId,
78 const IVtk_MeshType theMeshType)
80 vtkIdType aPointIdVTK = thePointId;
81 myPolyData->InsertNextCell (VTK_VERTEX, 1, &aPointIdVTK);
82 const vtkIdType aShapeIDVTK = theShapeID;
83 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
84 const vtkIdType aType = theMeshType;
85 myMeshTypes->InsertNextTupleValue (&aType);
88 //================================================================
89 // Function : InsertLine
91 //================================================================
92 void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
93 const IVtk_PointId thePointId1,
94 const IVtk_PointId thePointId2,
95 const IVtk_MeshType theMeshType)
97 vtkIdType aPoints[2] = { thePointId1, thePointId2 };
98 myPolyData->InsertNextCell (VTK_LINE, 2, aPoints);
99 const vtkIdType aShapeIDVTK = theShapeID;
100 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
101 const vtkIdType aType = theMeshType;
102 myMeshTypes->InsertNextTupleValue (&aType);
105 //================================================================
106 // Function : InsertLine
108 //================================================================
109 void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
110 const IVtk_PointIdList* thePointIds,
111 const IVtk_MeshType theMeshType)
113 if (!thePointIds->IsEmpty())
115 vtkIdList* anIdList = vtkIdList::New();
116 // Fill the vtk id list by ids from IVtk_PointIdList.
117 IVtk_PointIdList::Iterator anIterOfIds =
118 IVtk_PointIdList::Iterator(*thePointIds);
119 anIdList->Allocate(thePointIds->Extent());
120 for(; anIterOfIds.More(); anIterOfIds.Next())
122 anIdList->InsertNextId (anIterOfIds.Value());
125 myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList);
126 const vtkIdType aShapeIDVTK = theShapeID;
127 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
128 const vtkIdType aType = theMeshType;
129 myMeshTypes->InsertNextTupleValue (&aType);
134 //================================================================
135 // Function : InsertTriangle
137 //================================================================
138 void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID,
139 const IVtk_PointId thePointId1,
140 const IVtk_PointId thePointId2,
141 const IVtk_PointId thePointId3,
142 const IVtk_MeshType theMeshType)
144 vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
145 myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints);
146 const vtkIdType aShapeIDVTK = theShapeID;
147 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
148 const vtkIdType aType = theMeshType;
149 myMeshTypes->InsertNextTupleValue (&aType);