Skeleton.hpp

00001 #ifndef __FIBER_GRID_SKELETON_HPP
00002 #define __FIBER_GRID_SKELETON_HPP "Created 27.02.2001 21:42:27 by werner"
00003 
00004 #include "GridAPI.h"
00005 #include <field/Field.hpp>
00006 #include <memcore/TypeInfo.hpp>
00007 #include <set>
00008 #include <list>
00009 
00010 #include "FieldID.hpp"
00011 #include "BaseSpace.hpp"
00012 #include "FiberSpace.hpp"
00013 #include "Transformation.hpp"
00014 #include "Representation.hpp"
00015 #include "Chart.hpp"
00016 #include "Atlas.hpp"
00017 #include "GridContainer.hpp"
00018 
00019 namespace Fiber
00020 {
00021         using MemCore::WeakPtr;
00022         using MemCore::NullPtr;
00023         using std::set;
00024         using std::list;
00025 
00026 
00027 class   GRID_API FieldRef;
00028 
00037 class   GRID_API Skeleton : public BaseSpace, public RepresentationMap
00038 {
00039         WeakPtr<GridContainer>  myContainer;
00040 
00041 public: 
00042 
00044         Skeleton (const WeakPtr<GridContainer>&C); 
00045 
00047         ~Skeleton(); 
00048 
00049         using RepresentationMap::operator[]; 
00050         using RepresentationMap::makeRepresentation; 
00051         using RepresentationMap::operator(); 
00052         using RepresentationMap::size; 
00053         using RepresentationMap::Iterator;
00054         using RepresentationMap::iterate; 
00055 
00056 
00057 /*
00058         RefPtr<Representation> makeRepresentation(const Representer&D);
00059 
00061         Representation&operator[](const Representer&D);
00062 
00063         Representation&operator[](const BaseSpace&D)
00064         {
00065         Representer R = D.self(); 
00066                 return (*this)[R];
00067         }
00068 
00070         RefPtr<Representation> operator()(const Representer&D) const;
00071 
00073         int size() const; 
00074 */
00075 
00079 //      RefPtr<Representation> CartesianRepresentation() const;
00080 
00090         RefPtr<Representation> UniqueRepresentation() const; 
00091 
00100         RefPtr<Representation> FirstRepresentation() const; 
00101 
00102         override int Dims() const; 
00103 
00109         RefPtr<SizeInterface> getSize() const;
00110 
00111 //      FieldRef operator[](const string&fieldname);
00112 //      FieldRef operator[](const FieldID&fieldname);
00113 /*
00114         **
00115            Base class for callback iterators;
00116         *
00117         class   GRID_API Iterator
00118         {
00119         public:
00120                 virtual ~Iterator();
00121                 
00122                 virtual bool apply(const Representer&d, const Representation&R) = 0;
00123         };
00124 
00125         int iterate(Iterator&) const;
00126 */
00127 };
00128 
00129 typedef Skeleton Topology;
00130 
00132 typedef RefPtr<Skeleton> pSkeleton;
00133 
00135 typedef WeakPtr<Skeleton> wSkeleton;
00136 
00137 /*
00138 template <class CoordinateSystem>
00139         struct SkeletonRepresentation
00140 {
00141 static  Representation&makeDefaultRepresentation(const RefPtr<Skeleton>&SkelPtr, const RefPtr<GridAtlas>&GA)
00142         {
00143                 if (!SkelPtr) puts("ERROR: No SkelPtr!"); 
00144                 if (!GA)      puts("ERROR: No GridAtlas!"); 
00145 
00146         RefPtr<Chart> C = GridAtlas::CreateChart<CoordinateSystem>::global( (*GA) ); 
00147                 if (!C) puts("ERROR: Cannot create global chart"); 
00148 
00149         Representation&Rep = (*SkelPtr)[C]; 
00150 
00151                 return Rep;
00152         }
00153 };
00154 */
00155 
00160 class   GRID_API FieldRef
00161 {
00162         RefPtr<Skeleton>        SkelPtr;
00163         RefPtr<FieldID>         Id;
00164         RefPtr<Atlas>           myGridAtlas;
00165         string                  fieldname;
00166 
00167 public:
00168         FieldRef(const RefPtr<Skeleton>&S, const RefPtr<FieldID>&fid, const RefPtr<Atlas>&GA)
00169         : SkelPtr(S), Id(fid), myGridAtlas(GA)
00170         {}
00171 
00172         FieldRef(const RefPtr<Skeleton>&S, const string&fname, const RefPtr<Atlas>&GA)
00173         : SkelPtr(S), myGridAtlas(GA), fieldname(fname)
00174         {}
00175 
00176         ~FieldRef();
00177 
00178 /*
00179         template <class CoordinateSystem, class TensorType>
00180                 void operator=(const Tensor<CoordinateSystem, TensorType>&Value)
00181         {
00182         typedef Tensor<CoordinateSystem, TensorType> value_type;
00183         typedef MemArrayStorage<1, value_type, vector<value_type> > array_type;
00184 
00185         array_type*Data = new array_type(1);
00186                 Data->myArray()[0] = Value;
00187 
00188         RefPtr<Field> myField = new Field();
00189                 myField->setCreator( new MemCreativeArray(Data) ); 
00190 
00191 //      RefPtr<Chart> C = CreateChart<CoordinateSystem>::global( (*myGridAtlas) ); 
00192 //      Representation&Rep = (*SkelPtr)[C];
00193 
00194         Representation&Rep = SkeletonRepresentation<CoordinateSystem>::makeDefaultRepresentation(SkelPtr, myGridAtlas);
00195                 if (!Id)
00196                 {
00197                 FieldID&Fid = Rep[fieldname];
00198                         Id = &Fid;
00199                 }
00200 
00201                 Rep[ Id ] = myField;
00202         }
00203 */
00204 
00205 #if 0
00206 
00212         bool operator=(const double&Value)
00213         {
00214         typedef double value_type;
00215         typedef MemArrayStorage<1, value_type, vector<value_type> > array_type;
00216 
00217         array_type*Data = new array_type( MIndex(1) );
00218                 Data->myArray()[0] = Value;
00219 
00220         RefPtr<Representation> Rep = SkelPtr->DefaultRepresentation();
00221                 if (!Rep)
00222                         return false;
00223 
00224         RefPtr<Field> myField = new Field();
00225                 myField->setCreator( new MemCreativeArray(Data) );
00226 
00227                 if (!Id)
00228                 {
00229                 FieldID&Fid = (*Rep)[fieldname];
00230                         Id = &Fid;
00231                 }
00232 
00233                 (*Rep)[ Id ] = myField;
00234 
00235                 return true;
00236         }
00237 #endif
00238 
00239 
00240 /*
00241         template <class CoordinateSystem, class real>
00242         void operator=(const Point<CoordinateSystem, real>&Vertex)
00243         {
00244         typedef Point<CoordinateSystem, real> value_type;
00245         typedef MemArrayStorage<1, value_type, vector<value_type> > array_type; 
00246 
00247 //      RefPtr<Chart> C = CreateChart<CoordinateSystem>::global( (*myGridAtlas) ); 
00248 
00249 //              printf("Got chart named '%s' for storing points as %s (of %s)...\n", C->ID().c_str(), typeid(real).name(), typeid(Vertex).name() );
00250 
00251 //      Representation&Rep = (*SkelPtr)[C]; 
00252 
00253         Representation&Rep = SkeletonRepresentation<CoordinateSystem>::makeDefaultRepresentation(SkelPtr, myGridAtlas);
00254 
00255         array_type*Data = new array_type( MIndex(1) );
00256                 Data->myArray()[0] = Vertex;
00257 
00258         RefPtr<Field> myField = new Field();
00259                 myField->setCreator( new MemCreativeArray(Data) );
00260 
00261                 if (!Id)
00262                 {
00263                 FieldID&Fid = Rep[fieldname];
00264                         Id = &Fid;
00265                 }
00266 
00267                 Rep[ Id ] = myField;
00268         }
00269 */
00270 };
00271 
00272 } /* namespace Fiber */ 
00273 
00274 #endif /* __FIBER_GRID_SKELETON_HPP */