0026625: Possible wrong use of vtkSmartPointer<T> in IVtkVTK_ShapeData.cxx
[occt.git] / src / IVtkVTK / IVtkVTK_ShapeData.cxx
CommitLineData
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
24const char* const IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS = "SUBSHAPE_IDS";
25
26const char* const IVtkVTK_ShapeData::ARRNAME_MESH_TYPES = "MESH_TYPES";
27
28//! Handle implementation
913a4c4a 29
30
31//================================================================
32// Function : Constructor
33// Purpose :
34//================================================================
35IVtkVTK_ShapeData::IVtkVTK_ShapeData()
913a4c4a 36{
c16915c7 37 myPolyData = vtkSmartPointer<vtkPolyData>::New();
913a4c4a 38 myPolyData->Allocate();
39 myPolyData->SetPoints (vtkPoints::New());
40
c16915c7 41 mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New();
913a4c4a 42 mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
43 mySubShapeIDs->SetNumberOfComponents (1);
44 myPolyData->GetCellData()->AddArray (mySubShapeIDs);
45
c16915c7 46 myMeshTypes = vtkSmartPointer<vtkIdTypeArray>::New();
913a4c4a 47 myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES);
48 myMeshTypes->SetNumberOfComponents (1);
49 myPolyData->GetCellData()->AddArray (myMeshTypes);
50}
51
52//================================================================
53// Function : Destructor
54// Purpose :
55//================================================================
56IVtkVTK_ShapeData::~IVtkVTK_ShapeData()
57{ }
58
59//================================================================
60// Function : InsertCoordinate
61// Purpose :
62//================================================================
63IVtk_PointId IVtkVTK_ShapeData::InsertCoordinate (double theX,
64 double theY,
65 double theZ)
66{
67 return myPolyData->GetPoints()->InsertNextPoint (theX, theY, theZ);
68}
69
70//================================================================
71// Function : InsertVertex
72// Purpose :
73//================================================================
74void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID,
75 const IVtk_PointId thePointId,
76 const IVtk_MeshType theMeshType)
77{
78 vtkIdType aPointIdVTK = thePointId;
79 myPolyData->InsertNextCell (VTK_VERTEX, 1, &aPointIdVTK);
80 const vtkIdType aShapeIDVTK = theShapeID;
81 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
82 const vtkIdType aType = theMeshType;
83 myMeshTypes->InsertNextTupleValue (&aType);
84}
85
86//================================================================
87// Function : InsertLine
88// Purpose :
89//================================================================
90void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
91 const IVtk_PointId thePointId1,
92 const IVtk_PointId thePointId2,
93 const IVtk_MeshType theMeshType)
94{
95 vtkIdType aPoints[2] = { thePointId1, thePointId2 };
96 myPolyData->InsertNextCell (VTK_LINE, 2, aPoints);
97 const vtkIdType aShapeIDVTK = theShapeID;
98 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
99 const vtkIdType aType = theMeshType;
100 myMeshTypes->InsertNextTupleValue (&aType);
101}
102
103//================================================================
104// Function : InsertLine
105// Purpose :
106//================================================================
107void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
108 const IVtk_PointIdList* thePointIds,
109 const IVtk_MeshType theMeshType)
110{
111 if (!thePointIds->IsEmpty())
112 {
113 vtkIdList* anIdList = vtkIdList::New();
114 // Fill the vtk id list by ids from IVtk_PointIdList.
115 IVtk_PointIdList::Iterator anIterOfIds =
116 IVtk_PointIdList::Iterator(*thePointIds);
117 anIdList->Allocate(thePointIds->Extent());
118 for(; anIterOfIds.More(); anIterOfIds.Next())
119 {
120 anIdList->InsertNextId (anIterOfIds.Value());
121 }
122
123 myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList);
124 const vtkIdType aShapeIDVTK = theShapeID;
125 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
126 const vtkIdType aType = theMeshType;
127 myMeshTypes->InsertNextTupleValue (&aType);
128 anIdList->Delete();
129 }
130}
131
132//================================================================
133// Function : InsertTriangle
134// Purpose :
135//================================================================
136void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID,
137 const IVtk_PointId thePointId1,
138 const IVtk_PointId thePointId2,
139 const IVtk_PointId thePointId3,
140 const IVtk_MeshType theMeshType)
141{
142 vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
143 myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints);
144 const vtkIdType aShapeIDVTK = theShapeID;
145 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
146 const vtkIdType aType = theMeshType;
147 myMeshTypes->InsertNextTupleValue (&aType);
148}