913a4c4a |
1 | // Created on: 2011-10-14 |
2 | // Created by: Roman KOZLOV |
3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <IVtkVTK_ShapeData.hxx> |
a9660929 |
17 | |
18 | // prevent disabling some MSVC warning messages by VTK headers |
8e16477b |
19 | #include <Standard_WarningsDisable.hxx> |
913a4c4a |
20 | #include <vtkCellData.h> |
21 | #include <vtkDoubleArray.h> |
a2f76b15 |
22 | #include <vtkIdList.h> |
913a4c4a |
23 | #include <vtkPoints.h> |
24 | #include <vtkPolyData.h> |
8e16477b |
25 | #include <Standard_WarningsRestore.hxx> |
913a4c4a |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData,IVtk_IShapeData) |
28 | |
913a4c4a |
29 | //================================================================ |
30 | // Function : Constructor |
31 | // Purpose : |
32 | //================================================================ |
33 | IVtkVTK_ShapeData::IVtkVTK_ShapeData() |
913a4c4a |
34 | { |
c16915c7 |
35 | myPolyData = vtkSmartPointer<vtkPolyData>::New(); |
913a4c4a |
36 | myPolyData->Allocate(); |
a2f76b15 |
37 | myPolyData->SetPoints (vtkSmartPointer<vtkPoints>::New()); |
913a4c4a |
38 | |
c16915c7 |
39 | mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New(); |
68df8478 |
40 | mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS()); |
913a4c4a |
41 | mySubShapeIDs->SetNumberOfComponents (1); |
42 | myPolyData->GetCellData()->AddArray (mySubShapeIDs); |
43 | |
c16915c7 |
44 | myMeshTypes = vtkSmartPointer<vtkIdTypeArray>::New(); |
68df8478 |
45 | myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES()); |
913a4c4a |
46 | myMeshTypes->SetNumberOfComponents (1); |
47 | myPolyData->GetCellData()->AddArray (myMeshTypes); |
48 | } |
49 | |
50 | //================================================================ |
51 | // Function : Destructor |
52 | // Purpose : |
53 | //================================================================ |
54 | IVtkVTK_ShapeData::~IVtkVTK_ShapeData() |
55 | { } |
56 | |
57 | //================================================================ |
58 | // Function : InsertCoordinate |
59 | // Purpose : |
60 | //================================================================ |
61 | IVtk_PointId IVtkVTK_ShapeData::InsertCoordinate (double theX, |
62 | double theY, |
63 | double theZ) |
64 | { |
65 | return myPolyData->GetPoints()->InsertNextPoint (theX, theY, theZ); |
66 | } |
67 | |
68 | //================================================================ |
69 | // Function : InsertVertex |
70 | // Purpose : |
71 | //================================================================ |
72 | void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID, |
73 | const IVtk_PointId thePointId, |
74 | const IVtk_MeshType theMeshType) |
75 | { |
76 | vtkIdType aPointIdVTK = thePointId; |
77 | myPolyData->InsertNextCell (VTK_VERTEX, 1, &aPointIdVTK); |
e607bd3e |
78 | insertNextSubShapeId (theShapeID, theMeshType); |
913a4c4a |
79 | } |
80 | |
81 | //================================================================ |
82 | // Function : InsertLine |
83 | // Purpose : |
84 | //================================================================ |
85 | void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID, |
86 | const IVtk_PointId thePointId1, |
87 | const IVtk_PointId thePointId2, |
88 | const IVtk_MeshType theMeshType) |
89 | { |
90 | vtkIdType aPoints[2] = { thePointId1, thePointId2 }; |
91 | myPolyData->InsertNextCell (VTK_LINE, 2, aPoints); |
e607bd3e |
92 | insertNextSubShapeId (theShapeID, theMeshType); |
913a4c4a |
93 | } |
94 | |
95 | //================================================================ |
96 | // Function : InsertLine |
97 | // Purpose : |
98 | //================================================================ |
99 | void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID, |
100 | const IVtk_PointIdList* thePointIds, |
101 | const IVtk_MeshType theMeshType) |
102 | { |
103 | if (!thePointIds->IsEmpty()) |
104 | { |
a2f76b15 |
105 | vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New(); |
913a4c4a |
106 | // Fill the vtk id list by ids from IVtk_PointIdList. |
107 | IVtk_PointIdList::Iterator anIterOfIds = |
108 | IVtk_PointIdList::Iterator(*thePointIds); |
109 | anIdList->Allocate(thePointIds->Extent()); |
110 | for(; anIterOfIds.More(); anIterOfIds.Next()) |
111 | { |
112 | anIdList->InsertNextId (anIterOfIds.Value()); |
113 | } |
114 | |
115 | myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList); |
e607bd3e |
116 | insertNextSubShapeId (theShapeID, theMeshType); |
913a4c4a |
117 | } |
118 | } |
119 | |
120 | //================================================================ |
121 | // Function : InsertTriangle |
122 | // Purpose : |
123 | //================================================================ |
124 | void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID, |
125 | const IVtk_PointId thePointId1, |
126 | const IVtk_PointId thePointId2, |
127 | const IVtk_PointId thePointId3, |
128 | const IVtk_MeshType theMeshType) |
129 | { |
130 | vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 }; |
131 | myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints); |
e607bd3e |
132 | insertNextSubShapeId (theShapeID, theMeshType); |
913a4c4a |
133 | } |