From: <coe...@us...> - 2012-08-31 12:08:00
|
Revision: 418 http://mevislabmodules.svn.sourceforge.net/mevislabmodules/?rev=418&view=rev Author: coertmetz Date: 2012-08-31 12:07:51 +0000 (Fri, 31 Aug 2012) Log Message: ----------- CM: Added new interpolation options. Modified Paths: -------------- trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.cpp trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.h Modified: trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.cpp =================================================================== --- trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.cpp 2012-08-31 12:07:05 UTC (rev 417) +++ trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.cpp 2012-08-31 12:07:51 UTC (rev 418) @@ -66,11 +66,32 @@ _inputXMarkerListFld->setBaseValue(NULL); _outputXMarkerListFld = fields.addBase("outputXMarkerList"); _outputXMarkerListFld->setBaseValue(&_outputXMarkerList); + + // Mode field: equidistant or add intermediate points + std::vector< std::string > modes( 4 ); + modes[ 0 ] = "Equidistant"; + modes[ 1 ] = "Intermediate points"; + modes[ 2 ] = "Absolute marker indices"; + modes[ 3 ] = "Equidistant marker indices"; + _modeFld = fields.addEnum( "mode", modes ); + _modeFld->setEnumValue( 0 ); // Sample distance for output XMarkerList _sampleDistanceFld = fields.addFloat("sampleDistance"); _sampleDistanceFld->setFloatValue(0.5f); + // Number of intermediate points to add + _numIntermediatePointsFld = fields.addInt( "numberIntermediatePoints" ); + _numIntermediatePointsFld->setIntValue( 3 ); + + // Marker indices for third mode + _absoluteMarkerIndicesFld = fields.addString( "absoluteMarkerIndices" ); + _absoluteMarkerIndicesFld->setStringValue( "" ); + + // Number of total point for fourth mode + _numTotalPointsFld = fields.addInt( "numberTotalPoints" ); + _numTotalPointsFld->setIntValue( 3 ); + // Reactivate calls of handleNotification on field changes. handleNotificationOn(); } @@ -78,7 +99,7 @@ //---------------------------------------------------------------------------------- //! Handle field changes of the field field. //---------------------------------------------------------------------------------- -void LinearInterpolateXMarkerList::handleNotification (Field * /*field*/ ) +void LinearInterpolateXMarkerList::handleNotification ( Field * field ) { ML_TRACE_IN("LinearInterpolateXMarkerList::handleNotification ()"); @@ -86,60 +107,120 @@ _outputXMarkerList.clear(); Base * baseValue = _inputXMarkerListFld->getBaseValue(); - if (baseValue && BASE_IS_A(baseValue, XMarkerList)) { + if (baseValue && BASE_IS_A(baseValue, XMarkerList)) + { XMarkerList markers = *(XMarkerList*)baseValue; - if (markers.size()>1 && markers.isModified()) { - // Compute length XMarkerList - double length = 0.0; - for (size_t i=0; i<markers.size()-1; ++i) { - length += (markers[i].pos-markers[i+1].pos).length(); - } + if ( markers.size() > 1 && ( markers.isModified() || field == _modeFld || field == _numIntermediatePointsFld || field == _sampleDistanceFld ) ) + { + if ( _modeFld->getEnumValue() == 0 ) + { + // Compute length XMarkerList + double length = 0.0; + for (size_t i=0; i<markers.size()-1; ++i) { + length += (markers[i].pos-markers[i+1].pos).length(); + } - // Check sample distance setting - if (_sampleDistanceFld->getFloatValue()<=0.0f) { - _sampleDistanceFld->setFloatValue(1.0f); - } - // Get sample distance setting - const float sampleDistance = _sampleDistanceFld->getFloatValue(); + // Check sample distance setting + if (_sampleDistanceFld->getFloatValue()<=0.0f) { + _sampleDistanceFld->setFloatValue(1.0f); + } + // Get sample distance setting + const float sampleDistance = _sampleDistanceFld->getFloatValue(); - // Add first point - _outputXMarkerList.appendItem(markers[0]); + // Add first point + _outputXMarkerList.appendItem(markers[0]); - // The stepsize is the sampledistance - double stepSize = sampleDistance; - // Centerline length already processed - double curLength = 0.0; - // Current line segment position - unsigned int segmentPos = 0; + // The stepsize is the sampledistance + double stepSize = sampleDistance; + // Centerline length already processed + double curLength = 0.0; + // Current line segment position + unsigned int segmentPos = 0; - // Get first position - vec3 currentPos = markers[0].pos.getVec3(); - while (curLength < length && segmentPos<markers.size()-1) { - // Determine direction - vec3 direction = (vec6(markers[segmentPos+1].pos-markers[segmentPos].pos)).getVec3(); - direction.normalize(); - // Determine segment length - double segmentLength=(markers[segmentPos+1].pos-markers[segmentPos].pos).length(); - double curSegmentLength=0.0; - // Step in direction until next input point - while (curSegmentLength+stepSize<segmentLength) { + // Get first position + vec3 currentPos = markers[0].pos.getVec3(); + while (curLength < length && segmentPos<markers.size()-1) { + // Determine direction + vec3 direction = (vec6(markers[segmentPos+1].pos-markers[segmentPos].pos)).getVec3(); + direction.normalize(); + // Determine segment length + double segmentLength=(markers[segmentPos+1].pos-markers[segmentPos].pos).length(); + double curSegmentLength=0.0; + // Step in direction until next input point + while (curSegmentLength+stepSize<segmentLength) { + currentPos = currentPos + stepSize * direction; + curSegmentLength += stepSize; + curLength += stepSize; + _outputXMarkerList.appendItem(XMarker (currentPos)); + stepSize = sampleDistance; + } + // Determine rest length + stepSize = segmentLength-curSegmentLength; + // Update currentpos currentPos = currentPos + stepSize * direction; - curSegmentLength += stepSize; - curLength += stepSize; - _outputXMarkerList.appendItem(XMarker (currentPos)); - stepSize = sampleDistance; + curLength+=stepSize; + stepSize = sampleDistance - stepSize; + + // Increment current line segment position + ++segmentPos; } - // Determine rest length - stepSize = segmentLength-curSegmentLength; - // Update currentpos - currentPos = currentPos + stepSize * direction; - curLength+=stepSize; - stepSize = sampleDistance - stepSize; - - // Increment current line segment position - ++segmentPos; } + else if ( _modeFld->getEnumValue() == 1 ) + { + for ( size_t i = 0; i < markers.size() - 1; ++i ) + { + const float step = 1.0f / static_cast< float >( _numIntermediatePointsFld->getIntValue() + 1 ); + _outputXMarkerList.appendItem( markers.at( i ) ); + for ( float s = step; s <= 1.0f - step; s += step ) + { + XMarker marker( ( 1.0f - s ) * markers.at( i ).pos + s * markers.at( i + 1 ).pos ); + _outputXMarkerList.appendItem( marker ); + } + _outputXMarkerList.appendItem( markers.at( i + 1 ) ); + } + } + else if ( _modeFld->getEnumValue() == 2 ) + { + // Retrieve locations + std::stringstream timePoints ( _absoluteMarkerIndicesFld->getStringValue() ); + float timePoint; + std::vector< float > positions; + while ( timePoints >> timePoint ) + { + positions.push_back( timePoint ); + } + for ( size_t i = 0; i < positions.size(); ++i ) + { + const size_t prevIndex = static_cast< size_t >( positions[ i ] ); + const size_t nextIndex = static_cast< size_t >( positions[ i ] + 1 ); + const float fraction = positions[ i ] - static_cast< float >( prevIndex ); + if ( prevIndex >= 0 && nextIndex >= 0 && prevIndex < markers.size() && nextIndex < markers.size() ) + { + XMarker marker( ( 1.0f - fraction ) * markers.at( prevIndex ).pos + fraction * markers.at( nextIndex ).pos ); + marker.pos[ 0 ] = i; + _outputXMarkerList.appendItem( marker ); + } + else + { + std::cerr << "Position " << positions[ i ] << " outside marker range. Skipping point." << std::endl; + } + } + } + else if ( _modeFld->getEnumValue() == 3 ) + { + const float stepSize = static_cast< float >( markers.size() ) / ( static_cast< float >( _numTotalPointsFld->getIntValue() - 1 ) ); + int i = 0; + for ( float f = 0; f < static_cast< float >( markers.size() ) + stepSize / 10.0f; f += stepSize, ++i ) + { + const size_t prevIndex = std::min( markers.size() - 1, std::max( size_t( 0 ), static_cast< size_t >( f ) ) ); + const size_t nextIndex = std::min( markers.size() - 1, static_cast< size_t >( f + 1 ) ); + const float fraction = f - static_cast< float >( prevIndex ); + XMarker marker( ( 1.0f - fraction ) * markers.at( prevIndex ).pos + fraction * markers.at( nextIndex ).pos ); + marker.pos[ 0 ] = i; + _outputXMarkerList.appendItem( marker ); + } + } } } Modified: trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.h =================================================================== --- trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.h 2012-08-31 12:07:05 UTC (rev 417) +++ trunk/Community/General/Sources/ML/MLXMarkerListCommunityModules/InterpolateXMarkerList/mlLinearInterpolateXMarkerList.h 2012-08-31 12:07:51 UTC (rev 418) @@ -73,12 +73,16 @@ // ---------------------------------------------------------- //! Input and output XMarkerList fields - BaseField *_inputXMarkerListFld; - BaseField *_outputXMarkerListFld; + BaseField * _inputXMarkerListFld; + BaseField * _outputXMarkerListFld; XMarkerList _outputXMarkerList; //! Sample distance output XMarkerList - FloatField *_sampleDistanceFld; + EnumField * _modeFld; + FloatField * _sampleDistanceFld; + IntField * _numIntermediatePointsFld; + StringField * _absoluteMarkerIndicesFld; + IntField * _numTotalPointsFld; //@} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |