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> |
17 | #include <vtkCellArray.h> |
18 | #include <vtkCellData.h> |
19 | #include <vtkDoubleArray.h> |
20 | #include <vtkIdTypeArray.h> |
21 | #include <vtkPoints.h> |
22 | #include <vtkPolyData.h> |
23 | |
24 | const char* const IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS = "SUBSHAPE_IDS"; |
25 | |
26 | const char* const IVtkVTK_ShapeData::ARRNAME_MESH_TYPES = "MESH_TYPES"; |
27 | |
28 | //! Handle implementation |
29 | IMPLEMENT_STANDARD_HANDLE(IVtkVTK_ShapeData, IVtk_IShapeData) |
30 | IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData, IVtk_IShapeData) |
31 | |
32 | |
33 | //================================================================ |
34 | // Function : Constructor |
35 | // Purpose : |
36 | //================================================================ |
37 | IVtkVTK_ShapeData::IVtkVTK_ShapeData() |
38 | : myPolyData( vtkPolyData::New() ) |
39 | { |
40 | myPolyData->Allocate(); |
41 | myPolyData->SetPoints (vtkPoints::New()); |
42 | |
43 | mySubShapeIDs = vtkIdTypeArray::New(); |
44 | mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS); |
45 | mySubShapeIDs->SetNumberOfComponents (1); |
46 | myPolyData->GetCellData()->AddArray (mySubShapeIDs); |
47 | |
48 | myMeshTypes = vtkIdTypeArray::New(); |
49 | myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES); |
50 | myMeshTypes->SetNumberOfComponents (1); |
51 | myPolyData->GetCellData()->AddArray (myMeshTypes); |
52 | } |
53 | |
54 | //================================================================ |
55 | // Function : Destructor |
56 | // Purpose : |
57 | //================================================================ |
58 | IVtkVTK_ShapeData::~IVtkVTK_ShapeData() |
59 | { } |
60 | |
61 | //================================================================ |
62 | // Function : InsertCoordinate |
63 | // Purpose : |
64 | //================================================================ |
65 | IVtk_PointId IVtkVTK_ShapeData::InsertCoordinate (double theX, |
66 | double theY, |
67 | double theZ) |
68 | { |
69 | return myPolyData->GetPoints()->InsertNextPoint (theX, theY, theZ); |
70 | } |
71 | |
72 | //================================================================ |
73 | // Function : InsertVertex |
74 | // Purpose : |
75 | //================================================================ |
76 | void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID, |
77 | const IVtk_PointId thePointId, |
78 | const IVtk_MeshType theMeshType) |
79 | { |
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); |
86 | } |
87 | |
88 | //================================================================ |
89 | // Function : InsertLine |
90 | // Purpose : |
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) |
96 | { |
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); |
103 | } |
104 | |
105 | //================================================================ |
106 | // Function : InsertLine |
107 | // Purpose : |
108 | //================================================================ |
109 | void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID, |
110 | const IVtk_PointIdList* thePointIds, |
111 | const IVtk_MeshType theMeshType) |
112 | { |
113 | if (!thePointIds->IsEmpty()) |
114 | { |
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()) |
121 | { |
122 | anIdList->InsertNextId (anIterOfIds.Value()); |
123 | } |
124 | |
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); |
130 | anIdList->Delete(); |
131 | } |
132 | } |
133 | |
134 | //================================================================ |
135 | // Function : InsertTriangle |
136 | // Purpose : |
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) |
143 | { |
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); |
150 | } |