Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Common/vtkCellLinks.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkCellLinks.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00055 #ifndef __vtkCellLinks_h
00056 #define __vtkCellLinks_h
00057 
00058 #include "vtkObject.h"
00059 class vtkDataSet;
00060 class vtkCellArray;
00061 
00062 struct _vtkLink_s {
00063     unsigned short ncells;
00064     vtkIdType *cells;
00065 };
00066 
00067 class VTK_COMMON_EXPORT vtkCellLinks : public vtkObject 
00068 {
00069 public:
00070   static vtkCellLinks *New();
00071   vtkTypeMacro(vtkCellLinks,vtkObject);
00072 
00075   void Allocate(vtkIdType numLinks, vtkIdType ext=1000);
00076 
00078   _vtkLink_s &GetLink(vtkIdType ptId) {return this->Array[ptId];};
00079 
00081   unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;};
00082 
00084   void BuildLinks(vtkDataSet *data);
00085 
00087   void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity);
00088 
00090   vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;};
00091 
00094   vtkIdType InsertNextPoint(int numLinks);
00095 
00099   void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId);
00100 
00102   void DeletePoint(vtkIdType ptId);
00103 
00107   void RemoveCellReference(vtkIdType cellId, vtkIdType ptId);
00108 
00112   void AddCellReference(vtkIdType cellId, vtkIdType ptId);
00113 
00116   void ResizeCellList(vtkIdType ptId, int size);
00117 
00119   void Squeeze();
00120 
00122   void Reset();
00123 
00130   unsigned long GetActualMemorySize();
00131   
00134   void DeepCopy(vtkCellLinks *src);
00135 
00136 protected:
00137   vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
00138   ~vtkCellLinks();
00139 
00141   void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++;};
00142 
00143   void AllocateLinks(vtkIdType n);
00144 
00146 
00147   void InsertCellReference(vtkIdType ptId, unsigned short pos,
00148                            vtkIdType cellId);
00150 
00151   _vtkLink_s *Array;   // pointer to data
00152   vtkIdType Size;       // allocated size of data
00153   vtkIdType MaxId;     // maximum index inserted thus far
00154   vtkIdType Extend;     // grow array by this point
00155   _vtkLink_s *Resize(vtkIdType sz);  // function to resize data
00156 private:
00157   vtkCellLinks(const vtkCellLinks&);  // Not implemented.
00158   void operator=(const vtkCellLinks&);  // Not implemented.
00159 };
00160 
00161 
00162 inline void vtkCellLinks::InsertCellReference(vtkIdType ptId,
00163                                               unsigned short pos,
00164                                               vtkIdType cellId) 
00165 {
00166   this->Array[ptId].cells[pos] = cellId;
00167 }
00168 
00169 inline void vtkCellLinks::DeletePoint(vtkIdType ptId)
00170 {
00171   this->Array[ptId].ncells = 0;
00172   delete [] this->Array[ptId].cells;
00173   this->Array[ptId].cells = NULL;
00174 }
00175 
00176 inline void vtkCellLinks::InsertNextCellReference(vtkIdType ptId,
00177                                                   vtkIdType cellId) 
00178 {
00179   this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
00180 }
00181 
00182 inline void vtkCellLinks::RemoveCellReference(vtkIdType cellId, vtkIdType ptId)
00183 {
00184   vtkIdType *cells=this->Array[ptId].cells;
00185   int ncells=this->Array[ptId].ncells;
00186 
00187   for (int i=0; i < ncells; i++)
00188     {
00189     if (cells[i] == cellId)
00190       {
00191       for (int j=i; j < (ncells-1); j++)
00192         {
00193         cells[j] = cells[j+1];
00194         }
00195       this->Array[ptId].ncells--;
00196       break;
00197       }
00198     }
00199 }
00200 
00201 inline void vtkCellLinks::AddCellReference(vtkIdType cellId, vtkIdType ptId)
00202 {
00203   this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
00204 }
00205 
00206 inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size)
00207 {
00208   int newSize;
00209   vtkIdType *cells;
00210   
00211   newSize = this->Array[ptId].ncells + size;
00212   cells = new vtkIdType[newSize];
00213   memcpy(cells, this->Array[ptId].cells,
00214          this->Array[ptId].ncells*sizeof(vtkIdType));
00215   delete [] this->Array[ptId].cells;
00216   this->Array[ptId].cells = cells;
00217 }
00218 
00219 #endif
00220 

Generated on Thu Mar 28 14:19:14 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001