LineSet.hpp

00001 #ifndef __FIBER_GRID_TYPES_LINESET_HPP
00002 #define __FIBER_GRID_TYPES_LINESET_HPP
00003 
00004 #include "gridtypesDllApi.h"
00005 #include <grid/Grid.hpp>
00006 #include <eagle/PhysicalSpace.hpp>
00007 #include "Edges.hpp"
00008 //#include <memcore/Persistencer.hpp>
00009 //#include <memcore/AlzheimerCreator.hpp>
00010 
00011 //#define VERBOSE
00012 
00013 namespace Fiber
00014 {
00015 
00054 class   gridtypes_API   LineSet
00055 {
00056 public:
00057         typedef TypedArray<Eagle::PhysicalSpace::point>  CoordsArray_t;
00058         typedef MemArray<1, Eagle::PhysicalSpace::point> CoordsMemArray_t; 
00059 
00067         typedef uint32_t LineIndex_t; 
00068 
00072         typedef std::vector<LineSet::LineIndex_t> LineIndices_t; 
00073 
00077         typedef MemArray<1, LineIndices_t>      LinesetArray_t;
00078 
00079         typedef MemArray<1, Eagle::tvector3>    TangentialVector_t;
00080 
00081 
00082 
00089 static  SkeletonID PerLineSkeletonID()
00090         {
00091                 return SkeletonID(1,2);
00092         }
00093 
00094 static  SkeletonID ID()
00095         {
00096                 return PerLineSkeletonID();
00097         } 
00098 
00099         RefPtr<Skeleton> Vertices,
00100                          Lineset; 
00101 
00102         RefPtr<Representation>  CartesianVertices,
00103                                 LinesAsVertices;
00104 
00105         RefPtr<Field> 
00106                 Coords,
00107                 TangentialVectors,
00108                 LineIndices; 
00109 
00110 
00112 
00117 static const char TangentialVectorFieldName[];
00118 
00123 static const char NormalVectorFieldName[];
00124 
00131 static  const char ArcLengthFieldName[]; 
00132 
00136         struct  PredefinedFieldNames
00137         {
00138         static  const char
00139 
00146                 ProperTime[],
00147 
00152                 StepSize[],
00153 
00158                 Velocity[],
00159 
00164                 Speed[],
00165 
00170                 Energy[],
00171 
00175                 Curvature[],
00176 
00181                 Torsion[];
00182         }; 
00183 
00184         PredefinedFieldNames    FieldNames;
00185 
00186 
00187 
00191         LineSet(const WeakPtr<Grid>&G = NullPtr() );
00192 
00230         LineSet(const RefPtr<Grid>&G,
00231                 const RefPtr<CoordsArray_t>&Coords,
00232                 const RefPtr<LinesetArray_t>&Lineset,
00233                 const RefPtr<TangentialVector_t>&Tangents = NullPtr() ); 
00234 
00241         bool    operator=(const WeakPtr<Grid>&G); 
00242 
00248         LineSet&operator=(const LineSet&LS);
00249 
00251         ~LineSet(); 
00252 
00257         operator bool() const
00258         {
00259                 return LineIndices;
00260         } 
00261 
00265         bool operator!() const
00266         {
00267                 return !LineIndices;
00268         } 
00269 
00270 
00272         RefPtr<CoordsArray_t> getCoords( const RefPtr<FragmentID>& f = NullPtr() ) const
00273         {
00274                 if (!Coords)
00275                 {
00276                         puts("LineSet::getCoords() No Coords");
00277                         return NullPtr();
00278                 }
00279                 return Coords->getData( f );
00280         } 
00281         
00284         RefPtr<MemCore::ChunkBase> getCoordsAsMemChunk() const
00285         {
00286                 if (!Coords)
00287                         return NullPtr();
00288 
00289                 return (Coords->getData())->getChunk();
00290         } 
00291 
00294         RefPtr<MemCore::ChunkBase> getTangentsAsMemChunk() const
00295         {
00296                 if (!TangentialVectors)
00297                         return NullPtr();
00298 
00299                 return (TangentialVectors->getData())->getChunk();
00300         } 
00301         
00303         RefPtr<LinesetArray_t>  getLineset( const RefPtr<FragmentID>& f = NullPtr() ) const
00304         {
00305 #ifdef VERBOSE
00306                 puts("LineSet::getLineset() enter"); 
00307                 if(!f) puts("LineSet::getLineset() no fragment!");
00308 #endif 
00309                 if (!LineIndices)
00310                 {
00311                         puts("LineSet::getLineset() No LineIndices");
00312                         return NullPtr();
00313                 } 
00314                 
00315                 return LineIndices->getData( f );
00316         } 
00317 
00321 index_t NumberOfLines(const RefPtr<FragmentID>&f ) const; 
00322 
00323 index_t NumberOfLines() const;
00324 
00325 struct  NumberOfLinesIterator : FieldFragmentIterator
00326 {
00327         const LineSet& myLineSet;
00328         index_t numberOfLines;
00329 
00330         NumberOfLinesIterator( const LineSet& myLineSetP )
00331         :myLineSet(myLineSetP)
00332         , numberOfLines(0)
00333         {}
00334         
00335         bool apply( const RefPtr<FragmentID>&f,
00336                     const MemCore::StrongPtr<Fiber::CreativeArrayBase>&DC )
00337         {
00338                 numberOfLines += myLineSet.NumberOfLines( f ); 
00339                 return true;
00340         }
00341 }; 
00342 
00343 template<class T>
00344 struct FunctorPerFrag
00345 {
00346         bool exec( LineSet& myLineSet, const RefPtr<FragmentID>&f, const MemCore::StrongPtr<Fiber::CreativeArrayBase>&DC  )
00347         {
00348                 return true;
00349         }
00350 };
00351 
00352 template<class T>
00353 struct FunctorFragmentIterator : FieldFragmentIterator
00354 {
00355         LineSet& myLineSet;
00356         FunctorPerFrag<T>& Func;
00357 
00358         FunctorFragmentIterator( LineSet& myLineSetP, FunctorPerFrag<T>& FuncP  )
00359         : myLineSet(myLineSetP)
00360         , Func(FuncP)
00361         {}
00362         
00363         bool apply( const RefPtr<FragmentID>&f,
00364                     const MemCore::StrongPtr<Fiber::CreativeArrayBase>&DC )
00365         {
00366                 return Func.exec( myLineSet, f, DC);
00367         }
00368 }; 
00369 
00370 struct TComputeTVectorDerivative{};
00371 struct TComputeScalarDerivative{}; 
00372 struct TComputeUnitTVectorDerivative{};
00373 
00386         template <class Iterator>
00387         void    IterateLineSetFragment(Iterator&IC, const RefPtr<FragmentID>& f) const // would add lineset
00388         {
00389 #ifdef VERBOSE
00390                 puts("LineSet::IterateLineSetFragment() >>>> enter");fflush(stdout); 
00391                 if(!f) puts("LineSet::IterateLineSetFragment() no fragment!");
00392 #endif  
00393 
00394                 RefPtr<LinesetArray_t> tmpLineSet = getLineset( f ); 
00395 
00396 //              tmpLineSet.speak();
00397 
00398                 if ( !tmpLineSet  )  // here hauts ihn
00399                 {
00400                         puts("LineSet::IterateLineSetFragment() No LineSet!");fflush(stdout); 
00401                         if(f)
00402                                 std::cout << "          in " << f->Name() << std::endl;
00403                         return;
00404                 } 
00405         LinesetArray_t&LinesetArray = *tmpLineSet; 
00406 
00407                 if (!getCoords( f ) ) 
00408                 {               
00409                         puts("LineSet""IterateLineSetFragment() No Coords?!");fflush(stdout);
00410                         return; 
00411                 }
00412                 // check
00413         CoordsArray_t&VertexArray   = *getCoords( f );
00414                 
00415         const CreativeIterator<Eagle::PhysicalSpace::point>*V = VertexArray.creativeIterator(); 
00416         const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices = *V; 
00417 
00418 //      MemBase::Creator_t Crec; 
00419 //      RefPtr<MemArray<1, Eagle::tvector3> > TVecs = new MemArray<1, Eagle::tvector3>(V->count(), Crec );
00420 
00421                 for(index_t line = 0; line < LinesetArray.count(); line++)
00422                 {
00423                 const LineIndices_t&Line = LinesetArray[ line ]; 
00424                         IC.apply(Vertices, Line);
00425                 }
00426         } 
00427 
00428         template<class Iterator>
00429         void Iterate(Iterator&IC)
00430         {
00431 #ifdef VERBOSE
00432                 puts("LineSet::Iterate() enter");
00433 #endif
00434 /*
00435                 if(!LineIndices)
00436                       return; 
00437                 
00438 */
00439                 return;
00440                 // iterate over line indizes
00441         } 
00442 
00443         template <class Iterator>
00444         void    ApplyOnVertexFragment(Iterator&IC, const RefPtr<FragmentID>& f = NullPtr() ) const // would add lineset
00445         {
00446                 puts("LineSet::IterateVertexFragment() >>>> enter <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
00447 
00448                 // check for compatible line fragments here
00449 
00450                 // call from operator  
00451                 IterateLineSetFragment(IC, f);
00452         }
00453 
00454         struct  gridtypes_API CurveIterator
00455         {
00456                 virtual ~CurveIterator();
00457 
00458                 virtual void apply(const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices,
00459                                    const LineIndices_t&Line) = 0;
00460         };
00461 
00462         void    IterateCurves(CurveIterator&IC) const;
00463 
00464 
00465 static  void    ComputeCurveTangents(
00466                 MultiArray<1, Eagle::tvector3>&Tangents,
00467                 const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices,
00468                 const LineIndices_t&Line);
00469 
00474 static RefPtr<TangentialVector_t>
00475         ComputeTangentialVectors(const CoordsArray_t&Vertices,
00476                                  const LinesetArray_t&LinesetArray); 
00477 
00478 
00494         RefPtr<TangentialVector_t>
00495                 getTangentialVectors(const RefPtr<FragmentID>&f = NullPtr(), const string&FieldName = TangentialVectorFieldName); 
00496 
00501         RefPtr<TangentialVector_t>
00502                 getNormalVectors(const string&FieldName = NormalVectorFieldName);
00503 
00504 static RefPtr<TangentialVector_t>
00505         ComputeArcLength(const CoordsArray_t&Vertices,
00506                          const LinesetArray_t&LinesetArray); 
00507 
00508         RefPtr<FieldID> ComputeTVectorDerivative    (const RefPtr<Grid>&theGrid, const string&F, const string&dF = ""); 
00509         RefPtr<FieldID> ComputeScalarDerivative     (const RefPtr<Grid>&theGrid, const string&F, const string&dF = ""); 
00510         RefPtr<FieldID> ComputeUnitTVectorDerivative(const RefPtr<Grid>&theGrid, const string&F, const string&dF = ""); 
00511 
00512 
00513 
00514 struct  SetupStandardFieldIterator : FieldFragmentIterator
00515 {
00516         LineSet& myLineSet;
00517 
00518         const RefPtr<Grid>&theGrid;
00519 
00520         SetupStandardFieldIterator( LineSet& myLineSetP, const RefPtr<Grid>&theGridP )
00521         :myLineSet(myLineSetP)
00522         , theGrid(theGridP)
00523         {}
00524         
00525         bool apply( const RefPtr<FragmentID>&f,
00526                     const MemCore::StrongPtr<Fiber::CreativeArrayBase>&DC );
00527 
00528 }; 
00529 
00530 
00538         bool    setupStandardFields(const RefPtr<Grid>&theGrid);
00539 };
00540 
00541 
00542 class   gridtypes_API   LineSetWithEdges : public LineSet, public Edges
00543 {
00544 public:
00545         LineSetWithEdges(const WeakPtr<Grid>&G = NullPtr() );
00546         ~LineSetWithEdges();
00547 };
00548 
00549 } // namespace Fiber
00550 
00551 #endif // __FIBER_GRID_TYPES_LINESET_HPP