29 #include "WMPickingDVREvaluation.h"
30 #include "core/dataHandler/WDataSetScalar.h"
31 #include "core/graphicsEngine/WGERequirement.h"
32 #include "core/kernel/WKernel.h"
33 #include "core/ui/WUIRequirement.h"
36 #define WMPICKINGDVR_MAX_INTENS "Maximum intensity"
37 #define WMPICKINGDVR_FIRST_HIT "First hit "
38 #define WMPICKINGDVR_THRESHOLD "Opacity threshold "
39 #define WMPICKINGDVR_MOST_CONTRIBUTING "Most contributing"
40 #define WMPICKINGDVR_HIGHEST_OPACITY "Highest opacity "
41 #define WMPICKINGDVR_WYSIWYP "WYSIWYP "
63 return "Picking in DVR Evaluation";
68 return "Evaluate different picking techniques with regard to certain metrics.";
86 "Viewing and thus projection direction for DVR. "
87 "If [0,0,0], a multi-directional sampling will be performed.",
91 "Number of samples. Choose this appropriately for the settings used for the DVR itself.",
95 "Number of samples. For evaluating Delta_vi.",
109 "Select a picking method",
123 "Importance function.",
148 inline bool intersectPlaneWithRay(
WPosition* cutpoint,
158 double const d = dot( n, planePoint );
160 static const double MY_EPSILON = 1e-9;
161 if( std::abs( dot( n, rayDir ) ) < MY_EPSILON )
163 *cutpoint = planePoint;
167 double const t = ( d - dot( n, rayOrigin ) ) / ( dot( n, rayDir ) );
169 *cutpoint = rayOrigin + t * rayDir;
183 hit = intersectPlaneWithRay( &intersectionPoint,
190 && bbox.contains( intersectionPoint )
191 && dot( dir, intersectionPoint - origin ) > 0.0 )
194 return result = intersectionPoint;
198 hit = intersectPlaneWithRay( &intersectionPoint,
205 && bbox.contains( intersectionPoint )
206 && dot( dir, intersectionPoint - origin ) > 0.0 )
209 return result = intersectionPoint;
213 hit = intersectPlaneWithRay( &intersectionPoint,
220 && bbox.contains( intersectionPoint )
221 && dot( dir, intersectionPoint - origin ) > 0.0 )
224 return result = intersectionPoint;
228 hit = intersectPlaneWithRay( &intersectionPoint,
235 && bbox.contains( intersectionPoint )
236 && dot( dir, intersectionPoint - origin ) > 0.0 )
239 return result = intersectionPoint;
243 hit = intersectPlaneWithRay( &intersectionPoint,
250 && bbox.contains( intersectionPoint )
251 && dot( dir, intersectionPoint - origin ) > 0.0 )
254 return result = intersectionPoint;
258 hit = intersectPlaneWithRay( &intersectionPoint,
265 && bbox.contains( intersectionPoint )
266 && dot( dir, intersectionPoint - origin ) > 0.0 )
269 return result = intersectionPoint;
275 double sampleTFOpacity( std::shared_ptr< WDataSetSingle > transferFunctionData,
276 std::shared_ptr< WDataSetScalar > scalarData,
280 std::shared_ptr< WValueSetBase > transferFunctionValues = transferFunctionData->getValueSet();
282 double max = scalarData->getMax();
283 double min = scalarData->getMin();
286 double nominator = value - min;
287 double denominator = max - min;
289 if( denominator == 0.0 )
291 denominator = 0.0001;
295 double scalarPercentage = nominator / denominator;
296 int iColorIdx = scalarPercentage * transferFunctionValues->size();
298 const double normalizationFactor = 255.0;
299 return transferFunctionData->getSingleRawValue( iColorIdx * 4 + 3 ) / normalizationFactor;
305 bool interpolationSuccess =
false;
307 double value =
m_scalarDataSet->interpolate( pos, &interpolationSuccess );
308 WAssert( interpolationSuccess,
"Should not fail. Please file a bug report if it does." );
325 WAssert(
false,
"Should not fail. Internal module error or bug if it does." );
336 std::string pickModeName = selector.
at( 0 )->getName();
341 double accAlpha = 0.0;
342 double oldOpacity = 0.0;
346 for(
int sampleId = 0; sampleId <
m_sampleSteps->get(
true ); ++sampleId )
349 WPosition samplePos = startPos + sampleId * rayStep *.999999;
351 bool interpolationSuccess =
false;
352 double scalar =
m_scalarDataSet->interpolate( samplePos, &interpolationSuccess );
353 WAssert( interpolationSuccess,
"Should not fail. Please file a bug report if it does." );
355 if( pickModeName == WMPICKINGDVR_MAX_INTENS )
357 if( scalar > maxValue )
360 resultPos = samplePos;
363 else if( pickModeName == WMPICKINGDVR_FIRST_HIT )
368 resultPos = samplePos;
372 else if( pickModeName == WMPICKINGDVR_HIGHEST_OPACITY )
375 if( opacity > maxValue )
378 resultPos = samplePos;
381 else if( pickModeName == WMPICKINGDVR_MOST_CONTRIBUTING )
384 accAlpha = opacity + ( accAlpha - opacity * accAlpha );
385 double contribution = accAlpha - oldOpacity;
386 if( contribution > maxValue )
388 maxValue = contribution;
389 resultPos = samplePos;
391 oldOpacity = accAlpha;
395 WAssert(
false,
"This should not happen. Please file a bug report if it does." );
439 errorLog() <<
"[Invalid scalar field]";
447 errorLog() <<
"[Invalid transfer function data]";
453 regGrid = std::dynamic_pointer_cast< WGridRegular3D >( dsSingle->getGrid() );
460 m_bbox = regGrid->getBoundingBox();
464 std::vector< WVector3d > viewingDirections;
467 debugLog() <<
"Found [0,0,0] viewing direction -> performing multi-directional sampling.";
468 for(
int i_ID = -1; i_ID <= 1; ++i_ID )
470 for(
int j_ID = -1; j_ID <= 1; ++j_ID )
472 for(
int k_ID = -1; k_ID <= 1; ++k_ID )
477 viewingDirections.push_back( normalize( dir ) );
488 std::shared_ptr< WProgress > progress(
new WProgress(
"Sampling",
m_samplesEval->get(
true ) * viewingDirections.size() ) );
492 for(
size_t viewingDirId = 0; viewingDirId < viewingDirections.size(); ++viewingDirId )
494 debugLog() <<
"Sampling in direction " << viewingDirections[viewingDirId];
496 for(
int sampleId = 0; sampleId <
m_samplesEval->get(
true ); ++sampleId )
498 WAssert( regGrid->getOrigin() ==
WPosition( 0.0, 0.0, 0.0 ),
499 "0.999999 in the following works only if origin is at zero." );
501 size_t posId = sampleId * ( regGrid->size() /
m_samplesEval->get(
true ) );
504 WPosition samplePos = regGrid->getPosition( posId ) * 0.999999;
507 WVector3d vd = viewingDirections[viewingDirId];
509 deltaVI +=
importance( samplePos ) * distance;
516 deltaVI /=
m_samplesEval->get(
true ) * viewingDirections.size();
520 std::string pickModeName = selector.
at( 0 )->getName();
521 infoLog() << pickModeName <<
" deltaVI = " << deltaVI;
const vec_type & getMax() const
Gives the back upper right aka maximum corner.
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
std::shared_ptr< WDataSet > SPtr
Shared pointer abbreviation to a instance of this class.
This requirement ensures an up and running WGE.
std::shared_ptr< WGridRegular3DTemplate > SPtr
Convenience typedef for a std::shared_ptr< WGridRegular3DTemplate >.
A class containing a list of named items.
This class represents a subset of a WItemSelection.
virtual const std::shared_ptr< WItemSelectionItem > at(size_t index) const
Gets the selected item with the given index.
Someone should add some documentation here.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_transferFunction
The transfer function as an input data set.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< WItemSelection > m_pickingCriteriaList
Possible criteria.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
std::shared_ptr< WDataSetScalar > m_scalarDataSet
Input data as WDataSetScalar.
virtual void requirements()
Initialize requirements for this module.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_scalarData
Input connector for scalar data.
virtual void connectors()
Initialize the connectors this module is using.
virtual const std::string getName() const
Gives back the name of this module.
WPropInt m_sampleSteps
Number of samples along the ray.
WMPickingDVREvaluation()
A simple constructor.
WPosition visualizationMapping(const WPosition &pos, const WVector3d &viewDir)
viusalization mapping of directness model.
WPosition interactionMapping(const WPosition &startPos, const WVector3d &viewDir)
interaction Map of directness model.
WPosition intersectBoundingBoxWithRay(const WBoundingBox &bbox, const WPosition &origin, const WVector3d &dir)
Get position where a given ray intersects a given axis-aligned bounding box.
WPropSelection m_importanceFunctionCur
Current importance function.
virtual void properties()
Initialize the properties for this module.
WPropInt m_samplesEval
Number of samples for evaluating Delta_vi.
std::shared_ptr< WDataSetSingle > m_transferFunctionData
Transfer function as WDataSetSingle.
virtual ~WMPickingDVREvaluation()
A simple destructor.
virtual const std::string getDescription() const
Gives back a description of this module.
double importance(WPosition pos)
Importance function.
WPropPosition m_viewDirection
The viewing and thus projection direction.
WPropSelection m_pickingCriteriaCur
Current picking method.
WBoundingBox m_bbox
Bounding box of the treated data set.
std::shared_ptr< WItemSelection > m_impFuncList
Possible importance functions.
std::shared_ptr< WCondition > m_propCondition
Needed for recreating the geometry, incase when resolution changes.
Class representing a single module of OpenWalnut.
Requirements m_requirements
The list of requirements.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
This only is a 3d double vector.
Class managing progress inside of modules.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
This requirement ensures an up and running UI which properly implements the WUI interface.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
const double MAX_DOUBLE
Maximum double value.