32 #include "../common/WBoundingBox.h"
33 #include "../common/WColor.h"
34 #include "../common/WLogger.h"
35 #include "../common/WPredicateHelper.h"
36 #include "../common/WPropertyHelper.h"
37 #include "../common/datastructures/WFiber.h"
38 #include "../graphicsEngine/WGEUtils.h"
39 #include "WCreateColorArraysThread.h"
41 #include "WDataSetFibers.h"
42 #include "exceptions/WDHNoSuchDataSet.h"
47 static bool checkBelowTwo(
size_t number )
64 m_vertices( vertices ),
65 m_lineStartIndexes( lineStartIndexes ),
66 m_lineLengths( lineLengths ),
67 m_verticesReverse( verticesReverse ),
70 WAssert(
m_vertices->size() % 3 == 0,
"Invalid vertex array." );
81 m_vertices( vertices ),
82 m_lineStartIndexes( lineStartIndexes ),
83 m_lineLengths( lineLengths ),
84 m_verticesReverse( verticesReverse )
86 WAssert(
m_vertices->size() % 3 == 0,
"Invalid vertex array." );
90 for(
size_t i = 0; i < vertices->size()/3; ++i )
92 m_bb.
expandBy( (*vertices)[ 3 * i + 0 ], (*vertices)[ 3 * i + 1 ], (*vertices)[ 3 * i + 2 ] );
105 m_vertices( vertices ),
106 m_lineStartIndexes( lineStartIndexes ),
107 m_lineLengths( lineLengths ),
108 m_verticesReverse( verticesReverse ),
110 m_vertexParameters( 1, vertexParameters )
112 WAssert(
m_vertices->size() % 3 == 0,
"Invalid vertex array." );
124 m_vertices( vertices ),
125 m_lineStartIndexes( lineStartIndexes ),
126 m_lineLengths( lineLengths ),
127 m_verticesReverse( verticesReverse ),
128 m_vertexParameters( 1, vertexParameters )
130 WAssert(
m_vertices->size() % 3 == 0,
"Invalid vertex array." );
134 for(
size_t i = 0; i < vertices->size()/3; ++i )
136 m_bb.
expandBy( (*vertices)[ 3 * i + 0 ], (*vertices)[ 3 * i + 1 ], (*vertices)[ 3 * i + 2 ] );
145 m_tangents = std::shared_ptr< std::vector< float > >(
new std::vector<float>(
size ) );
147 std::shared_ptr< std::vector< float > > globalColors(
new std::vector<float>(
size ) );
148 std::shared_ptr< std::vector< float > > localColors(
new std::vector<float>(
size ) );
149 std::shared_ptr< std::vector< float > > customColors(
new std::vector<float>(
size ) );
177 m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
178 new ColorScheme(
"Global Color",
"Colors direction by using start and end vertex per fiber.", NULL, globalColors,
ColorScheme::RGB )
181 m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
182 new ColorScheme(
"Local Color",
"Colors direction by using start and end vertex per segment.", NULL, localColors,
ColorScheme::RGB )
186 for(
size_t i = 0; i <
size; ++i )
188 ( *customColors )[i] = ( *globalColors )[i];
190 m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
191 new ColorScheme(
"Custom Color",
"Colors copied from the global colors, will be used for bundle coloring.",
216 return "WDataSetFibers";
221 return "Contains tracked fiber data.";
270 WAssert( verts != 0,
"If there is color there has to be vertices!" );
272 size_t cols = colors->size();
273 if( cols / verts == 3 )
277 else if( cols / verts == 4 )
282 m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
283 new ColorScheme( name, description, NULL, colors, mode )
294 while( i != l->get().end() )
296 if( std::static_pointer_cast< const ColorScheme >( *i )->getColor() == colors )
298 i = l->get().erase( i );
313 std::shared_ptr< ColorScheme > ci = std::static_pointer_cast< ColorScheme >( *i );
314 if( ci->getColor() == oldColors )
316 ci->setColor( newColors );
327 if( i == l->get().end() )
329 throw WDHNoSuchDataSet( std::string(
"Color scheme with specified name could not be found." ) );
332 return std::static_pointer_cast< ColorScheme >( *i );
343 return std::static_pointer_cast< ColorScheme >( l->get()[ idx ] );
348 return std::static_pointer_cast< ColorScheme >(
m_colorProp->get().at( 0 ) );
405 tangent = point - pointNext;
410 tangent = pointBefore - point;
416 tangent = pointBefore - pointNext;
419 return normalize( tangent );
429 WAssert( numTract < m_lineLengths->
size(),
"WDataSetFibers: out of bounds - invalid tract number requested." );
432 size_t vIdx = ( *m_lineStartIndexes )[ numTract ] * 3;
433 for(
size_t vertexNum = 0; vertexNum < ( *m_lineLengths )[ numTract ]; ++vertexNum )
463 : m_fibers( fibers ),
469 : m_fibers( iter.m_fibers ),
470 m_index( iter.m_index )
542 WFiberIterator::operator bool()
const
544 return m_fibers != NULL && m_index < numPoints();
549 WAssert( m_index < m_fibers->size(),
"" );
648 for( ( si, se ) = this->
segments(); si != se; ++si )
664 : m_fibers( fibers ),
665 m_fiberIndex( fbIdx ),
672 : m_fibers( iter.m_fibers ),
673 m_fiberIndex( iter.m_fiberIndex ),
674 m_index( iter.m_index ),
675 m_reverse( iter.m_reverse )
737 WAssert( m_fiberIndex < m_fibers->size(),
"Index must be smaller than the number of fibers!" );
738 WAssert( m_index < m_fibers->getLengthOfLine(
m_fiberIndex ),
"Point index must be smaller than the number of points!" );
761 wlog::warn(
"FiberPointsIterator" ) <<
"Comparing a reverse and a normal iterator!";
777 WFiberPointsIterator::operator bool()
const
779 return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex );
803 switch( scheme->getMode() )
807 double r = scheme->getColor()->operator[]( 1 * v + 0 );
808 ret.set( r, r, r, 1.0 );
813 double r = scheme->getColor()->operator[]( 3 * v + 0 );
814 double g = scheme->getColor()->operator[]( 3 * v + 1 );
815 double b = scheme->getColor()->operator[]( 3 * v + 2 );
816 ret.set( r, g, b, 1.0 );
821 double r = scheme->getColor()->operator[]( 4 * v + 0 );
822 double g = scheme->getColor()->operator[]( 4 * v + 1 );
823 double b = scheme->getColor()->operator[]( 4 * v + 2 );
824 double a = scheme->getColor()->operator[]( 4 * v + 3 );
825 ret.set( r, g, b, a );
829 ret.set( 1.0, 1.0, 1.0, 1.0 );
859 : m_fibers( fibers ),
860 m_fiberIndex( fbIdx ),
867 : m_fibers( iter.m_fibers ),
868 m_fiberIndex( iter.m_fiberIndex ),
869 m_index( iter.m_index ),
870 m_reverse( iter.m_reverse )
923 wlog::warn(
"WFiberSegmentsIterator" ) <<
"Comparing a reverse and a normal iterator!";
939 WFiberSegmentsIterator::operator bool()
const
941 return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex ) - 1;
957 return osg::Vec3( 0.0, 0.0, 0.0 );
964 return distance( *
start(), *
end() );
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
Thread for computing directional color coding of fibers.
Should be thrown when an invalid index is used to get a WDataSet from the WSubject.
Item used in the selection below also containing color info.
ColorMode
different kinds of color arrays can be used in this class.
@ GRAY
gray value per vertex
Represents a simple set of WFibers.
std::size_t getStartIndex(std::size_t fiber) const
Get the index of the first vertex of a given fiber.
void addColorScheme(WDataSetFibers::ColorArray colors, std::string name, std::string description)
This method adds a new color scheme to the list of available colors.
WPosition getTangent(size_t fiber, size_t vertex) const
calculates the tangent for a point on the fiber
std::shared_ptr< std::vector< size_t > > IndexArray
Index list indexing fibers in VertexArray in terms of vertex numbers.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
void replaceColorScheme(WDataSetFibers::ColorArray oldColors, WDataSetFibers::ColorArray newColors)
Replaces the specified old color scheme by the new color scheme.
WPosition getPosition(size_t fiber, size_t vertex) const
returns the position in space for a vertex of a given fiber
void removeColorScheme(WDataSetFibers::ColorArray colors)
This method removes the specified color scheme from the list and triggers an update.
void setLineParameters(std::vector< LineParemeterArray > parameters)
Set an array to be the list of line parameters.
LineParemeterArray getLineParameters(size_t parameterIndex=0) const
Get the parameter values for each line.
TangentArray getTangents() const
Returns an array containing the tangents of the fibers at the vertices.
VertexParemeterArray getVertexParameters(size_t parameterIndex=0) const
Get the parameter values for each vertex.
VertexArray getVertices() const
Getter for the lines' vertices.
void init()
This does the common initialisation of the constructors.
std::shared_ptr< std::vector< float > > TangentArray
Tangents at each vertex in VertexArray.
size_t size() const
Get number of tracts in this data set.
std::shared_ptr< std::vector< size_t > > LengthArray
Lengths of fibers in terms of vertices.
LengthArray getLineLengths() const
Return the number of vertices for all lines.
std::shared_ptr< std::vector< double > > VertexParemeterArray
Parameter storage for each vertex.
std::vector< LineParemeterArray > m_lineParameters
Parameter array.
WFiber operator[](size_t numTract) const
Constructs a WFiber out of the given tract number.
const WPropSelection getColorSchemeProperty() const
Returns the property controlling the color scheme selection.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
IndexArray getLineStartIndexes() const
Return the indices that indicate at which vertex ID each line begins in the vertex array.
OW_API_DEPRECATED const_iterator end() const
Returns an iterator pointing beyond the last fiber.
std::vector< VertexParemeterArray > m_vertexParameters
Parameter array.
LengthArray m_lineLengths
Line vector that contains the number of vertices for each line.
IndexArray getVerticesReverse() const
Returns a reverse lookup table that allow do find out which vertex belongs to which line.
const std::shared_ptr< ColorScheme > getColorScheme() const
Convenience method returning the currently selected scheme.
WBoundingBox getBoundingBox() const
Get the bounding box.
IndexArray m_verticesReverse
Reverse lookup table for which point belongs to which fiber.
TangentArray m_tangents
Point vector for tangents at each vertex, used for fake tubes.
void setSelectedColorScheme(size_t idx)
Sets the selected color scheme.
WBoundingBox m_bb
Axis aligned bounding box for all tract-vertices of this dataset.
std::size_t getLengthOfLine(std::size_t fiber) const
Returns the number of points for a given fiber.
WDataSetFibers()
Constructs a new set of tracts.
WIteratorRange< WFiberIterator > fibers() const
Creates a range of iterators that allows for forward iteration of the fibers in this dataset.
virtual const std::string getName() const
Gets the name of this prototype.
size_t getNbVertices() const
Getter for the total number of vertices over all lines.
void setVertexParameters(std::vector< VertexParemeterArray > parameters)
Set the given array of parameters to be the vertex parameters of this fiber dataset.
virtual const std::string getDescription() const
Gets the description for this prototype.
std::shared_ptr< WItemSelection > m_colors
An array of color arrays.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
std::shared_ptr< std::vector< double > > LineParemeterArray
Parameter storage for each line.
const std::shared_ptr< ColorScheme > getColorScheme(std::string name) const
Get the color scheme with the specified name.
OW_API_DEPRECATED const_iterator begin() const
Returns an iterator to the first fiber of the dataset.
IndexArray m_lineStartIndexes
Line vector that contains the start index of its first point for each line.
VertexArray m_vertices
Point vector for all fibers.
WPropSelection m_colorProp
Property keeping track of the active color in m_colors.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
Base class for all data set types.
std::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION".
std::shared_ptr< WProperties > m_properties
The property object for the dataset.
An iterator for fibers of a fiber dataset.
WFiberIterator operator-(size_t n) const
Minus operator.
OW_API_DEPRECATED WFiberPointsIterator begin()
Creates a point iterator for forward iteration, pointing to the first point of the fiber.
OW_API_DEPRECATED WFiberPointsIterator end()
Creates a point iterator for forward iteration, pointing beyond the last point of the fiber.
bool operator==(WFiberIterator const &rhs) const
Compare to another fiber iterator.
~WFiberIterator()
Destructor.
std::size_t numPoints() const
Returns the number of points of the current fiber.
OW_API_DEPRECATED WFiberSegmentsIterator srend()
Returns a backward iterator to the invalid segment before the first (i.e.
WIteratorRange< WFiberPointsIterator > pointsReverse() const
Creates a range of iterators that allows for reverse iteration of the points of the fiber this iterat...
WFiberIterator & operator=(WFiberIterator const &iter)
Copy operator.
std::size_t m_index
The current index in the fiber data.
OW_API_DEPRECATED WFiberPointsIterator rend()
Creates a point iterator for backward iteration, pointing beyond the first point of the fiber.
WIteratorRange< WFiberSegmentsIterator > segmentsReverse() const
Creates a range of iterators that allows for reverse iteration of the segments of the fiber this iter...
WIteratorRange< WFiberSegmentsIterator > segments() const
Creates a range of iterators that allows for forward iteration of the segments of the fiber this iter...
WIteratorRange< WFiberPointsIterator > points() const
Creates a range of iterators that allows for forward iteration of the points of the fiber this iterat...
std::size_t getLineStartIndex() const
Get the index in the point array where the points data starts for this line.
OW_API_DEPRECATED WFiberSegmentsIterator sbegin()
Returns a forward iterator to the first segment.
bool operator!=(WFiberIterator const &rhs) const
Compare to another fiber iterator.
WIteratorRangeUnpacker< WFiberIterator > operator,(WFiberIterator &other)
Creates a temporary object that is used to unpack an iterator range to two iterators.
OW_API_DEPRECATED WFiberSegmentsIterator send()
Returns a forward iterator to the invalid segment after the last (i.e.
double getFiberLength() const
The length of the line.
WDataSetFibers const * m_fibers
The pointer to the fibers.
WFiberIterator()
Constructor.
OW_API_DEPRECATED WFiberPointsIterator rbegin()
Creates a point iterator for backward iteration, pointing to the last point of the fiber.
WFiberIterator & operator++()
Increment operator.
WFiberIterator operator+(size_t n) const
Plus operator.
OW_API_DEPRECATED WFiberSegmentsIterator srbegin()
Returns a backward iterator to the last segment.
std::size_t getIndex() const
Get the index of the line.
WFiberIterator & operator--()
Decrement operator.
An iterator for iterating the points of a fiber.
bool m_reverse
Whether to iterate backwards.
WFiberPointsIterator operator+(size_t n)
Plus operator.
bool operator==(WFiberPointsIterator const &rhs) const
Compare to another point iterator.
std::size_t m_index
The index of the current point.
WPosition getTangent() const
The tangent of the point.
WFiberPointsIterator operator-(size_t n)
Minus operator.
WIteratorRangeUnpacker< WFiberPointsIterator > operator,(WFiberPointsIterator &other)
Creates a temporary object that is used to unpack an iterator range to two iterators.
WColor getColor() const
Return the color of the point.
WPosition operator*() const
Returns the coordinates of the point currently pointed to.
WFiberPointsIterator & operator=(WFiberPointsIterator const &iter)
Copy operator.
std::size_t m_fiberIndex
The index of the fiber.
bool operator!=(WFiberPointsIterator const &rhs) const
Compare to another point iterator.
std::size_t getBaseIndex() const
Calculates the index of this point in the dataset arrays.
WFiberPointsIterator & operator--()
Decrement operator.
WFiberPointsIterator & operator++()
Increment operator.
WFiberPointsIterator()
Default contructor.
double getParameter(double def=0.0, size_t parameterIndex=0) const
Returns the parameter specified in the vertex parameter array of the dataset.
~WFiberPointsIterator()
Destructor.
WDataSetFibers const * m_fibers
The pointer to the fibers.
An iterator for iterating the segments of a fiber.
WFiberPointsIterator start() const
Returns an iterator to the starting point of the segment.
WFiberSegmentsIterator & operator++()
Increment operator.
bool m_reverse
Whether to iterate backwards.
osg::Vec3 direction() const
Returns the vector from the starting point position to the end point position.
std::size_t m_index
The index of the current point.
WFiberSegmentsIterator()
Default contructor.
WFiberSegmentsIterator & operator--()
Decrement operator.
WIteratorRangeUnpacker< WFiberSegmentsIterator > operator,(WFiberSegmentsIterator &other)
Creates a temporary object that is used to unpack an iterator range to two iterators.
std::size_t m_fiberIndex
The index of the fiber.
double length() const
Returns the length of the segment.
~WFiberSegmentsIterator()
Destructor.
WFiberPointsIterator end() const
Returns an iterator to the end point of the segment.
bool operator!=(WFiberSegmentsIterator const &rhs) const
Compare to another segment iterator.
WFiberSegmentsIterator & operator=(WFiberSegmentsIterator const &iter)
Copy operator.
bool operator==(WFiberSegmentsIterator const &rhs) const
Compare to another segment iterator.
WDataSetFibers const * m_fibers
The pointer to the fibers.
Represents a neural pathway.
A class containing a list of named items.
A temporary used to unpack an iterator range into two iterators.
void reserve(size_type new_capacity)
Wrapper around std::vector member function.
void push_back(const value_type &value)
Wrapper around std::vector member function.
This only is a 3d double vector.
This class tests against the getName() method of the instances of type T.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
S::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
S::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
virtual void run()
Run thread.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
int32_t PV_INT
base type used for every WPVInt
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
WStreamedLogger warn(const std::string &source)
Logging a warning message.