Version: 6.3.1

src/CONVERTOR/VISU_MergeFilterUtilities.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00021 //  File   : 
00022 //  Author : 
00023 //  Module : SALOME
00024 //  $Header: /home/server/cvs/VISU/VISU_SRC/src/CONVERTOR/VISU_MergeFilterUtilities.hxx,v 1.3.2.1.6.1.8.1 2011-06-02 06:00:16 vsr Exp $
00025 //
00026 #ifndef VISU_MergeFilterUtilities_H
00027 #define VISU_MergeFilterUtilities_H
00028 
00029 #include <string>
00030 #include <vtkDataSet.h>
00031 
00032 class vtkDataSet;
00033 class vtkPolyData;
00034 class vtkUnstructuredGrid;
00035 class vtkIntArray;
00036 
00037 using namespace std;
00038 #include <set>
00039 #include <vector>
00040 #include <map>
00041 
00042 namespace VISU
00043 {
00044   class TFieldList;
00045 
00046   typedef int TCellId;
00047   typedef int TEntityId;
00048   typedef std::pair<TCellId, TEntityId> TObjectId;
00049 
00050   typedef std::set<TObjectId> TObjectIdSet;
00051   typedef std::vector<TObjectId> TObjectIdArray;
00052 
00053   typedef int TTupleId;
00054   typedef std::map<TObjectId, TTupleId> TObjectId2TupleIdMap;
00055 
00056   typedef int TTupleCellID;
00057   typedef int GeometryCellID;
00058   typedef std::vector<TTupleCellID> TCellIdArray;
00059   typedef std::map<GeometryCellID, TCellIdArray> TObjectId2TupleGaussIdMap;
00060   
00061   //---------------------------------------------------------------
00062   typedef vtkFieldData* (vtkDataSet::* TGetFieldData)();
00063 
00064   //---------------------------------------------------------------
00065   struct TGetCellData
00066   {
00067     vtkFieldData*
00068     operator()(vtkDataSet* theDataSet)
00069     {
00070       return (vtkFieldData*)(theDataSet->GetCellData());
00071     }
00072   };
00073 
00074 
00075   //---------------------------------------------------------------
00076   struct TGetPointData
00077   {
00078     vtkFieldData*
00079     operator()(vtkDataSet* theDataSet)
00080     {
00081       return (vtkFieldData*)(theDataSet->GetPointData());
00082     }
00083   };
00084 
00085   void
00086   GetObjectId2TupleIdMap(vtkIntArray *theArray, 
00087                          TObjectId2TupleIdMap& theObjectId2TupleIdMap);
00088 
00089   void
00090   GetObjectId2TupleGaussIdArray(vtkIntArray *theArray,
00091                                 TObjectId2TupleGaussIdMap& theObjectId2TupleGaussIdMap);
00092   
00093   template<class TGetFieldData>
00094   vtkIntArray*
00095   GetIDMapper(VISU::TFieldList* theFieldList,
00096               TGetFieldData theGetFieldData,
00097               const char* theFieldName);
00098 
00099   template<class TGetFieldData>
00100   vtkIntArray*
00101   GetIDMapper(vtkDataSet* theIDMapperDataSet,
00102               TGetFieldData theGetFieldData,
00103               const char* theFieldName);
00104 
00105   bool
00106   IsDifferent(vtkIntArray *theFirstIDMapper,
00107               vtkIntArray *theSecondIDMapper);
00108 
00109   void
00110   GetIntersection(vtkIntArray *theFirstIDMapper,
00111                   vtkIntArray *theSecondIDMapper,
00112                   TObjectIdArray& theResult);
00113 
00114   //---------------------------------------------------------------
00115   bool
00116   Execute(vtkUnstructuredGrid *theInput,
00117           vtkUnstructuredGrid *theOutput,
00118           vtkDataSet* theScalarsDataSet,
00119           vtkDataSet* theVectorsDataSet,
00120           vtkDataSet* theNormalsDataSet,
00121           vtkDataSet* theTCoordsDataSet,
00122           vtkDataSet* theTensorsDataSet,
00123           TFieldList* theFieldList,
00124           bool theIsMergingInputs);
00125 
00126 
00127   //---------------------------------------------------------------
00128   bool
00129   Execute(vtkPolyData *theInput,
00130           vtkPolyData *theOutput,
00131           vtkDataSet* theScalarsDataSet,
00132           vtkDataSet* theVectorsDataSet,
00133           vtkDataSet* theNormalsDataSet,
00134           vtkDataSet* theTCoordsDataSet,
00135           vtkDataSet* theTensorsDataSet,
00136           TFieldList* theFieldList,
00137           bool theIsMergingInputs);
00138 
00139   //---------------------------------------------------------------
00140   class TFieldNode
00141   {
00142   public:
00143     TFieldNode(const char* name, vtkDataSet* ptr=0)
00144     {
00145       int length = static_cast<int>(strlen(name));
00146       if (length > 0) {
00147         this->Name = new char[length+1];
00148         strcpy(this->Name, name);
00149       } else {
00150         this->Name = 0;
00151       }
00152       this->Ptr = ptr;
00153       this->Next = 0;
00154     }
00155     ~TFieldNode()
00156     {
00157       delete[] this->Name;
00158     }
00159 
00160     const char* GetName()
00161     {
00162       return Name;
00163     }
00164     vtkDataSet* Ptr;
00165     TFieldNode* Next;
00166   private:
00167     TFieldNode(const TFieldNode&) {}
00168     void operator=(const TFieldNode&) {}
00169     char* Name;
00170   };
00171 
00172 
00173   //---------------------------------------------------------------
00174   class TFieldList
00175   {
00176   public:
00177     TFieldList()
00178     {
00179       this->First = 0;
00180       this->Last = 0;
00181     }
00182     ~TFieldList()
00183     {
00184       TFieldNode* node = this->First;
00185       TFieldNode* next;
00186       while(node){
00187         next = node->Next;
00188         delete node;
00189         node = next;
00190       }
00191     }
00192 
00193 
00194     void Add(const char* name, vtkDataSet* ptr)
00195     {
00196       TFieldNode* newNode = new TFieldNode(name, ptr);
00197       if (!this->First) {
00198         this->First = newNode;
00199         this->Last = newNode;
00200       } else {
00201         this->Last->Next = newNode;
00202         this->Last = newNode;
00203       }
00204     }
00205 
00206     friend class TFieldListIterator;
00207     
00208   private:
00209     TFieldNode* First;
00210     TFieldNode* Last;
00211   };
00212   
00213 
00214   //---------------------------------------------------------------
00215   class TFieldListIterator
00216   {
00217   public:
00218     TFieldListIterator(TFieldList* list)
00219     {
00220       this->List = list;
00221       this->Position = 0;
00222     }
00223     void Begin()
00224     {
00225       this->Position = this->List->First;
00226     }
00227     void Next()
00228     {
00229       if (this->Position) {
00230         this->Position = this->Position->Next;
00231       }
00232     }
00233     int End()
00234     {
00235       return this->Position ? 0 : 1;
00236     }
00237     TFieldNode* Get()
00238     {
00239       return this->Position;
00240     }
00241     
00242   private:
00243     TFieldNode* Position;
00244     TFieldList* List;
00245   };
00246   
00247 
00248   //---------------------------------------------------------------
00249 }
00250 
00251 #endif
00252 
00253 
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS