1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkCellTypes.h,v $
6 Date: $Date: 2002/02/01 06:35:43 $
7 Version: $Revision: 1.1.1.1 $
10 Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
12 This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
13 The following terms apply to all files associated with the software unless
14 explicitly disclaimed in individual files. This copyright specifically does
15 not apply to the related textbook "The Visualization Toolkit" ISBN
16 013199837-4 published by Prentice Hall which is covered by its own copyright.
18 The authors hereby grant permission to use, copy, and distribute this
19 software and its documentation for any purpose, provided that existing
20 copyright notices are retained in all copies and that this notice is included
21 verbatim in any distributions. Additionally, the authors grant permission to
22 modify this software and its documentation for any purpose, provided that
23 such modifications are not distributed without the explicit consent of the
24 authors and that existing copyright notices are retained in all copies. Some
25 of the algorithms implemented by this software are patented, observe all
26 applicable patent law.
28 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
29 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
30 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
31 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
34 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
36 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
37 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
40 =========================================================================*/
41 // .NAME vtkCellTypes - object provides direct access to cells in vtkCellArray and type information
42 // .SECTION Description
43 // This class is a supplemental object to vtkCellArray to allow random
44 // access into cells as well as representing cell type information. The
45 // "location" field is the location in the vtkCellArray list in terms of an
46 // integer offset. An integer offset was used instead of a pointer for easy
47 // storage and inter-process communication. The type information is defined
48 // in the file vtkCellType.h.
50 // Sometimes this class is used to pass type information independent of the
51 // random access (i.e., location) information. For example, see
52 // vtkDataSet::GetCellTypes(). If you use the class in this way, you can use
53 // a location value of -1.
55 // vtkCellArray vtkCellLinks
57 #ifndef __vtkCellTypes_h
58 #define __vtkCellTypes_h
60 #include "vtkReferenceCount.h"
61 #include "vtkCellType.h"
64 unsigned char type; //from CellType.h
65 int loc; //location in associated CellArray object
68 class VTK_EXPORT vtkCellTypes : public vtkReferenceCount
71 vtkCellTypes() : Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
72 vtkCellTypes(int sz, int ext);
74 static vtkCellTypes *New() {return new vtkCellTypes;};
75 int Allocate(int sz=512, int ext=1000);
76 const char *GetClassName() {return "vtkCellTypes";};
78 void InsertCell(int id, unsigned char type, int loc);
79 int InsertNextCell(unsigned char type, int loc);
80 void DeleteCell(int cellId);
82 //special operations to pass type information
83 int GetNumberOfTypes();
84 int IsType(unsigned char type);
85 int InsertNextType(unsigned char type);
86 unsigned char GetCellType(int id);
88 //special operations used for managing data location offsets
89 int GetCellLocation(int id);
90 _vtkCell_s &GetCell(int id);
96 _vtkCell_s *Array; // pointer to data
97 int Size; // allocated size of data
98 int MaxId; // maximum index inserted thus far
99 int Extend; // grow array by this point
100 _vtkCell_s *Resize(int sz); // function to resize data
104 // Return a reference to a cell list structure.
105 inline _vtkCell_s &vtkCellTypes::GetCell(int id)
107 return this->Array[id];
111 // Return the type of cell.
112 inline unsigned char vtkCellTypes::GetCellType(int cellId)
114 return this->Array[cellId].type;
118 // Return the location of the cell in the associated vtkCellArray.
119 inline int vtkCellTypes::GetCellLocation(int cellId)
121 return this->Array[cellId].loc;
125 // Delete cell by setting to NULL cell type.
126 inline void vtkCellTypes::DeleteCell(int cellId)
128 this->Array[cellId].type = VTK_NULL_ELEMENT;
132 // Return the number of types in the list.
133 inline int vtkCellTypes::GetNumberOfTypes()
135 return (this->MaxId + 1);
139 // Return 1 if type specified is contained in list; 0 otherwise.
140 inline int vtkCellTypes::IsType(unsigned char type)
142 int numTypes=this->GetNumberOfTypes();
144 for (int i=0; i<numTypes; i++)
145 if ( type == this->GetCellType(i)) return 1;
150 // Add the type specified to the end of the list. Range checking is performed.
151 inline int vtkCellTypes::InsertNextType(unsigned char type)
153 return this->InsertNextCell(type,-1);