FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
LineSet.hpp
1#ifndef __FIBER_GRID_TYPES_LINESET_HPP
2#define __FIBER_GRID_TYPES_LINESET_HPP
3
4#include "gridtypesDllApi.h"
5#include <grid/Grid.hpp>
6#include <eagle/PhysicalSpace.hpp>
7#include "Edges.hpp"
8
9#include <functional>
10
11//#define VERBOSE
12
13namespace Fiber
14{
15
55{
56public:
59
68
73
78
80
81
82
90 {
91 return SkeletonID(1,2);
92 }
93
94static SkeletonID ID()
95 {
96 return PerLineSkeletonID();
97 }
98
99static SkeletonID IDFragmented()
100 {
101 return SkeletonID(3,0);
102 }
103
104 RefPtr<Skeleton> Vertices,
105 Lineset;
106
107 RefPtr<Representation> CartesianVertices,
108 LinesAsVertices;
109
110 RefPtr<Field>
111 Coords,
112 TangentialVectors,
113 LineIndices;
114
115
117
122static const char TangentialVectorFieldName[];
123
128static const char NormalVectorFieldName[];
129
136static const char ArcLengthFieldName[];
137
142 {
143 static const char
144
152
158
164
169 Speed[],
170
176
181
187 };
188
189 PredefinedFieldNames FieldNames;
190
191
192
196 LineSet(const WeakPtr<Grid>&G = NullPtr() );
197
235 LineSet(const RefPtr<Grid>&G,
236 const RefPtr<CoordsArray_t>&Coords,
237 const RefPtr<LinesetArray_t>&Lineset,
238 const RefPtr<TangentialVector_t>&Tangents = NullPtr() );
239
240 /*
241 Alternative constructor to create a LineSet from a reference
242 to a Grid object. Be cautious that when using the [] operator
243 then an existing Grid will be reused from a Bundle and modified
244 here. Using the newGrid() function is safer, but this function is
245 convenient when operating in situation where it is ensured that
246 the respective Grid does not exist or modifying it is not harmful.
247 @code
248 BundlePtr B;
249 LineSet theLines(B[0.]["LineSet"], CoordsArray, LinesetArray );
250 @endcode
251 */
252 LineSet(Grid&G,
253 const RefPtr<CoordsArray_t>&Coords,
254 const RefPtr<LinesetArray_t>&Lineset,
255 const RefPtr<TangentialVector_t>&Tangents = NullPtr() )
256 : LineSet(G.self(), Coords, Lineset, Tangents )
257 {}
258
265 bool operator=(const WeakPtr<Grid>&G);
266
273
275 ~LineSet();
276
281 operator bool() const
282 {
283 return LineIndices.valid();
284 }
285
289 bool operator!() const
290 {
291 return !LineIndices;
292 }
293
294
297 {
298 if (!Coords)
299 {
300 return NullPtr();
301 }
302 return Coords->getData( f );
303 }
304
308 {
309 if (!Coords)
310 return NullPtr();
311
312 return -(Coords->getData());
313 }
314
318 {
319 if (!TangentialVectors)
320 return NullPtr();
321
322 return -(TangentialVectors->getData());
323 }
324
327 {
328 if (!LineIndices)
329 {
330 Verbose(0) << "LineSet::getLineset() No LineIndices";
331 return NullPtr();
332 }
333
334 return LineIndices->getData( f );
335 }
336
338
339 template<int N, class T>
340 RefPtr<Fiber::MemBase> extractDataFromField(const std::string& fieldname,
341 RefPtr<FragmentID> fragID = NullPtr())
342 {
343 RefPtr<Fiber::Field> f = (*LinesAsVertices)(fieldname);
344 if(!f)
345 {
346 f = (*CartesianVertices)(fieldname);
347 if (!f)
348 {
349 Verbose(0) << fieldname << ": NullPtr() in LineSet::extractDataFromField [f]";
350 return NullPtr();
351 }
352 }
353
354 RefPtr<Fiber::MemArray<N,T> > mem = f->getData(fragID);
355 if (!mem)
356 {
357 Verbose(0) << fieldname << ": NullPtr() in LineSet::extractDataFromField [mem]";
358 return NullPtr();
359 }
360
361 return mem;
362 }
363
364
368 index_t NumberOfLines(const RefPtr<FragmentID>&f ) const;
369
370 index_t NumberOfLines() const;
371
373 {
374 const LineSet& myLineSet;
375 index_t numberOfLines;
376
378 :myLineSet(myLineSetP)
379 , numberOfLines(0)
380 {}
381
382 bool apply( const RefPtr<FragmentID>&f,
384 {
385 numberOfLines += myLineSet.NumberOfLines( f );
386 return true;
387 }
388 };
389
390
391 /* Iterators */
392
393 using CoordinateFragmentIterator =
394 std::function<bool(const RefPtr<CoordsArray_t>&,
396
397 using CoordinateFragmentIteratorWithVertexID =
400
401 void iterateCompatibleFragmentation(const CoordinateFragmentIterator&);
402 void iterateCompatibleFragmentation(const CoordinateFragmentIteratorWithVertexID&);
403
404
405 using LineVertexIterator = std::function<bool(const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices,
408
424 void iterateCompatibleFragmentation(const LineVertexIterator&);
425
426
427
428
429
430
431
432
433 template<class T> struct FunctorPerFrag
434 {
435 bool exec( LineSet& myLineSet, const RefPtr<FragmentID>&f, const MemCore::StrongPtr<Fiber::CreativeArrayBase>&DC )
436 {
437 return true;
438 }
439 };
440
441 template<class T>
443 {
444 LineSet& myLineSet;
445 FunctorPerFrag<T>& Func;
446
448 : myLineSet(myLineSetP)
449 , Func(FuncP)
450 {}
451
452 bool apply( const RefPtr<FragmentID>&f,
454 {
455 return Func.exec( myLineSet, f, DC);
456 }
457 };
458
459
460
464
465#ifdef USE_DEPRECATED_LINESET_FUNCTIONS
466
479 template <class Iterator>
480 void IterateLineSetFragment(Iterator&IC, const RefPtr<FragmentID>& f) const // would add lineset
481 {
482 RefPtr<LinesetArray_t> tmpLineSet = getLineset( f );
483
484 if ( !tmpLineSet ) // here hauts ihn
485 {
486 return;
487 }
488
489 LinesetArray_t&LinesetArray = *tmpLineSet;
490
491 if (!getCoords( f ) )
492 {
493 Verbose(0) << "LineSet::IterateLineSetFragment() No Coords?!";
494 return;
495 }
496 // check
497 CoordsArray_t&VertexArray = *getCoords( f );
498
499 const CreativeIterator<Eagle::PhysicalSpace::point>*V = VertexArray.creativeIterator();
500 const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices = *V;
501
502// MemBase::Creator_t Crec;
503// RefPtr<MemArray<1, Eagle::tvector3> > TVecs = new MemArray<1, Eagle::tvector3>(V->count(), Crec );
504
505 for(index_t line = 0; line < LinesetArray.count(); line++)
506 {
507 const LineIndices_t&Line = LinesetArray[ line ];
508 IC.apply(Vertices, Line);
509 }
510 }
511
512 template<class Iterator>
513 [[deprecated("Use iterateCompatibleFragmentation() instead.")]]
514 void Iterate(Iterator&IC) const
515 {
516/*
517 if(!LineIndices)
518 return;
519
520*/
521 // do an iterations over vertexfragments here instead of just calling for one, MR
522 ApplyOnVertexFragment(IC, NullPtr() );
523
524 return;
525 // iterate over line indizes
526 }
527
528 template <class Iterator>
529 void ApplyOnVertexFragment(Iterator&IC, const RefPtr<FragmentID>& f = NullPtr() ) const // would add lineset
530 {
531 // check for compatible line fragments here
532 // call from operator
533 IterateLineSetFragment(IC, f);
534 }
535
536 struct [[deprecated("Use iterateCompatibleFragmentation() instead.")]] CurveIterator;
537
538 struct gridtypes_API CurveIterator
539 {
540 virtual ~CurveIterator();
541
542 virtual void apply(const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices,
543 const LineIndices_t&Line) = 0;
544 };
545
546 [[deprecated("Use iterateCompatibleFragmentation() instead.")]]
547 void IterateCurves(CurveIterator&IC) const;
548
549#endif // USE_DEPRECATED_LINESET_FUNCTIONS
550
551
552static void ComputeCurveTangents(
553 MultiArray<1, Eagle::tvector3>&Tangents,
554 const CreativeIterator<Eagle::PhysicalSpace::point>&Vertices,
555 const LineIndices_t&Line);
556
561static RefPtr<TangentialVector_t>
562 ComputeTangentialVectors(const CoordsArray_t&Vertices,
563 const LinesetArray_t&LinesetArray);
564
565
581 RefPtr<TangentialVector_t>
582 getTangentialVectors(const RefPtr<FragmentID>&f = NullPtr(), const string&FieldName = TangentialVectorFieldName);
583
588 RefPtr<TangentialVector_t>
589 getNormalVectors(const string&FieldName = NormalVectorFieldName);
590
591static RefPtr<TangentialVector_t>
592 ComputeArcLength(const CoordsArray_t&Vertices,
593 const LinesetArray_t&LinesetArray);
594
595 RefPtr<FieldID> ComputeTVectorDerivative (const RefPtr<Grid>&theGrid, const string&F, const string&dF = "");
596 RefPtr<FieldID> ComputeScalarDerivative (const RefPtr<Grid>&theGrid, const string&F, const string&dF = "");
597 RefPtr<FieldID> ComputeUnitTVectorDerivative(const RefPtr<Grid>&theGrid, const string&F, const string&dF = "");
598
599
600
602{
603 LineSet& myLineSet;
604
605 const RefPtr<Grid>&theGrid;
606
608 :myLineSet(myLineSetP)
609 , theGrid(theGridP)
610 {}
611
612 bool apply( const RefPtr<FragmentID>&f,
614
615};
616
617
625 bool setupStandardFields(const RefPtr<Grid>&theGrid);
626
627 RefPtr<Field> getFieldOnLines(const string& field_name ) const;
628
629static uint32_t getNumberOfDistinctIndices( const LineSet::LinesetArray_t& lines );
630
631
632 LineSet orient(bool CounterClockWise);
633
634
635 /* convert fragmented line set to unfragmented */
636static std::string unfragment(const Grid&GridIn, Grid&GridOut);
637
638
639};
640
641
643{
644public:
647};
648
649} // namespace Fiber
650
651#endif // __FIBER_GRID_TYPES_LINESET_HPP
constexpr complex< _Tp > & operator=(const _Tp &)
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
basic_string< char > string
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Identify the edges on a skeleton within a Grid.
Definition Edges.hpp:35
Base class for iterators over the fragments of a field.
Definition FragmentID.hpp:249
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
Implementation of an Iterator to a sequence of elements, which might be contiguous or a projection of...
Definition vector/Iterator.hpp:525
Definition LineSet.hpp:643
A set of lines stored on a Grid.
Definition LineSet.hpp:55
RefPtr< LinesetArray_t > getLineset(const RefPtr< FragmentID > &f=NullPtr()) const
Return edges information.
Definition LineSet.hpp:326
uint32_t LineIndex_t
The index type used for line set indices.
Definition LineSet.hpp:67
RefPtr< MemCore::ChunkBase > getCoordsAsMemChunk() const
Return Mem ChunkBase of Coordinates Added by Bidur.
Definition LineSet.hpp:307
RefPtr< CoordsArray_t > getCoords(const RefPtr< FragmentID > &f=NullPtr()) const
Return coordinate array.
Definition LineSet.hpp:296
bool operator!() const
Inverse operator of the line indices check.
Definition LineSet.hpp:289
index_t NumberOfLines(const RefPtr< FragmentID > &f) const
Return the number of lines stored here.
Definition LineSet.cpp:221
std::vector< LineSet::LineIndex_t > LineIndices_t
A vector of line indices.
Definition LineSet.hpp:72
static SkeletonID PerLineSkeletonID()
A Skeleton ID for sets of edges, thereby defining lines.
Definition LineSet.hpp:89
RefPtr< Fiber::MemBase > extractDataFromField(const std::string &fieldname, RefPtr< FragmentID > fragID=NullPtr())
Return data arrays stored on the line.
Definition LineSet.hpp:340
MemArray< 1, LineIndices_t > LinesetArray_t
An array of line indices.
Definition LineSet.hpp:77
RefPtr< MemCore::ChunkBase > getTangentsAsMemChunk() const
Return Mem ChunkBase of Tangential Vectors Added by Bidur.
Definition LineSet.hpp:317
Class for N-dimensional MultiArrays with MemCore memory management.
Definition MemArray.hpp:34
Identifier for Skeletons within a Grid.
Definition SkeletonID.hpp:24
An intermediate class that allows to operate on the pure type information of some memory array.
Definition TypedArray.hpp:58
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
RefPtr< MemArray< 1, Eagle::tvector3 > > ComputeTangentialVectors(const MemArray< 1, Eagle::point3 > &Vertices, const MemArray< 1, std::vector< index_t > > &EdgesArray, const MemBase::Creator_t &Crec)
Compute tangential vectors along a set of lines.
Definition TangentialVectors.cpp:14
RefPtr< MemArray< 1, Eagle::tvector3 > > getTangentialVectors(Grid &G, const string &TangentialVectorFieldName)
Compute tangential vectors in a grid object, which has a set of lines defined.
Definition TangentialVectors.cpp:47
const char TangentialVectorFieldName[]
A default name for the field that holds the tangential vectors of a grid describing lines.
Definition TangentialVectors.cpp:10
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
std::nullptr_t NullPtr
Compute the curvature of a curve, which is a line with Velocity given.
Definition CurveOperators.hpp:320
Compute the energy of a curve, which is .
Definition CurveOperators.hpp:211
Compute the proper time of a curve, which is a line with Velocity given.
Definition CurveOperators.hpp:251
Compute the step size of a curve.
Definition CurveOperators.hpp:95
Store the velocity of curve, which determines its parameterization.
Definition CurveOperators.hpp:140
Definition LineSet.hpp:443
Definition LineSet.hpp:434
Definition LineSet.hpp:373
Predefined field names on linesets.
Definition LineSet.hpp:142