struct VectorFieldParameters {
long fieldHandlerId;
- string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name - only used to color the glyphs
ScalarBarRangeType scalarBarRange;
ColorMapType colorMap;
};
// Python variables:
int id = GeneratePythonId();
- std::ostringstream oss_o, oss_d, oss_l, oss_s;
+ std::ostringstream oss_o, oss_d, oss_l, oss_s, oss_r;
oss_o << "__obj" << id;
oss_s << "__srcObj" << id;
oss_d << "__disp" << id;
oss_l << "__lut" << id;
+ oss_r << "__range" << id;
_objVar = oss_o.str();
_srcObjVar = oss_s.str();
_dispVar = oss_d.str();
_lutVar = oss_l.str();
+ _rangeVar = oss_r.str();
}
MEDPresentation::~MEDPresentation()
* Needs the LUT, so to be called after selectColorMap for the first time.
*/
void
-MEDPresentation::fixScalarBarTitle()
+MEDPresentation::scalarBarTitle()
{
// get selected component name:
- std::string compoName("Magnitude");
+ std::string compoName;
if (_selectedComponentIndex != -1)
{
std::ostringstream oss1;
oss1 << MEDPresentation::PROP_COMPONENT << _selectedComponentIndex;
compoName = getStringProperty(oss1.str());
}
+ else
+ {
+ if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) == 1)
+ compoName = "";
+ else
+ compoName = "Magnitude";
+ }
std::ostringstream oss;
oss << "pvs.GetScalarBar(" << _lutVar << ").ComponentTitle = '" << compoName << "';";
pushAndExecPyLine(oss.str()); oss.str("");
throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
}
pushAndExecPyLine(oss.str());
+
+ selectFieldComponent(); // somehow PV keeps the LUT parameters of the previous presentation, so better reset this.
}
void
throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
}
pushAndExecPyLine(oss.str()); oss.str("");
+ // Get min-max
+ oss << _rangeVar << " = [" << _dispVar << ".LookupTable.RGBPoints[0], " << _dispVar << ".LookupTable.RGBPoints[-4]];";
+ pushAndExecPyLine(oss.str());
+
+ // Adapt scalar bar title
+ scalarBarTitle();
}
+
+
int
MEDPresentation::GeneratePythonId()
{
void showScalarBar();
void rescaleTransferFunction();
void selectColorMap();
- void fixScalarBarTitle();
+ void scalarBarTitle();
void resetCameraAndRender();
virtual void internalGeneratePipeline();
std::string _dispVar;
///! ParaView LUT variable in the Python scripting commands
std::string _lutVar;
+ ///! ParaView variable in Python holding the data range
+ std::string _rangeVar;
private:
///! Pipeline elements
selectFieldComponent();
// The component has changed, we need to rescale the scalar bar to adapt:
rescaleTransferFunction();
- fixScalarBarTitle(); // should be fixed in PV one day!
pushAndExecPyLine("pvs.Render();");
}
}
// Set number of contours
setNumberContours();
colorBy("POINTS"); // necessarily POINTS because of the conversion above
+
showScalarBar();
- rescaleTransferFunction();
selectColorMap();
+ rescaleTransferFunction();
resetCameraAndRender();
}
return tmp._retn();
}
-MEDCALC::VectorFieldParameters*
+MEDCALC::VectorFieldParameters
MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
{
- MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters();
- _getParameters<MEDPresentationVectorField>(presentationID, *p);
- MEDCALC::VectorFieldParameters_var tmp(p);
- return tmp._retn();
+ MEDCALC::VectorFieldParameters p;
+ _getParameters<MEDPresentationVectorField>(presentationID, p);
+ return p;
}
MEDCALC::PointSpriteParameters*
MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID);
MEDCALC_EXPORT MEDCALC::ContourParameters getContourParameters(MEDPresentation::TypeID presentationID);
MEDCALC_EXPORT MEDCALC::SlicesParameters* getSlicesParameters(MEDPresentation::TypeID presentationID);
- MEDCALC_EXPORT MEDCALC::VectorFieldParameters* getVectorFieldParameters(MEDPresentation::TypeID presentationID);
+ MEDCALC_EXPORT MEDCALC::VectorFieldParameters getVectorFieldParameters(MEDPresentation::TypeID presentationID);
MEDCALC_EXPORT MEDCALC::PointSpriteParameters* getPointSpriteParameters(MEDPresentation::TypeID presentationID);
MEDCALC_EXPORT void updateMeshView(MEDPresentation::TypeID, const MEDCALC::MeshViewParameters&);
pushAndExecPyLine(oss.str()); oss.str("");
showScalarBar();
- rescaleTransferFunction();
selectColorMap();
+ rescaleTransferFunction();
resetCameraAndRender();
}
showObject();
colorBy(_fieldType);
showScalarBar();
- rescaleTransferFunction();
selectColorMap();
+ rescaleTransferFunction();
resetCameraAndRender();
// Retrieve Python object for internal storage:
colorBy(_fieldType);
showScalarBar();
- rescaleTransferFunction();
selectColorMap();
+ rescaleTransferFunction();
resetCameraAndRender();
}
{
}
+void
+MEDPresentationVectorField::autoScale()
+{
+ std::ostringstream oss;
+ oss << "import medcalc;";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << _objVar << ".ScaleFactor = 2.0*medcalc.ComputeCellAverageSize(__srcObj0)/(" << _rangeVar
+ << "[1]-" << _rangeVar << "[0]);";
+ pushAndExecPyLine(oss.str()); oss.str("");
+}
+
void
MEDPresentationVectorField::internalGeneratePipeline()
{
fillAvailableFieldComponents();
if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) <= 1)
{
- const char * msg = "Vector field presentation does not work for scalar field!"; // this message will appear in GUI too
+ const char * msg = "Vector field presentation does not work for scalar field!"; // this message will appear in GUI too
STDLOG(msg);
throw KERNEL::createSalomeException(msg);
}
pushAndExecPyLine(oss.str()); oss.str("");
oss << _objVar << ".GlyphMode = 'All Points';";
pushAndExecPyLine(oss.str()); oss.str("");
-// oss << _objVar << "GlyphTransform = 'Transform2';"; // not sure this is really needed?
-// pushAndExecPyLine(oss.str()); oss.str("");
+ oss << _objVar << "GlyphTransform = 'Transform2';"; // not sure this is really needed?
+ pushAndExecPyLine(oss.str()); oss.str("");
oss << _objVar << ".ScaleFactor = 0.1;";
pushAndExecPyLine(oss.str()); oss.str("");
- // Auto-tuning of the scale factor:
-// oss << "import medcalc; medcalc.SetDefaultScaleFactor(active=" << _objVar << ");";
-// pushAndExecPyLine(oss.str()); oss.str("");
colorBy("POINTS");
showScalarBar();
- rescaleTransferFunction();
selectColorMap();
+ rescaleTransferFunction();
+
+ autoScale(); // to be called after transfer function so we have the range
+
resetCameraAndRender();
}
if (params.fieldHandlerId != _params.fieldHandlerId)
throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
- if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
- updateComponent<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(std::string(params.displayedComponent));
if (params.scalarBarRange != _params.scalarBarRange)
- updateScalarBarRange<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(params.scalarBarRange);
+ {
+ updateScalarBarRange<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(params.scalarBarRange);
+ autoScale();
+ pushAndExecPyLine("pvs.Render();");
+ }
if (params.colorMap != _params.colorMap)
updateColorMap<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(params.colorMap);
}
protected:
virtual void internalGeneratePipeline();
+ void autoScale();
private:
MEDCALC::VectorFieldParameters _params;
if (connect)
{
+ QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) );
QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) );
}
void MEDWidgetHelper::releaseWidget()
{
+ QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
QObject::disconnect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) );
QObject::disconnect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) );
if (connect)
{
// Connect combo box changes
- QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
- _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
}
}
{
MEDWidgetHelper::releaseWidget();
- QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
- _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
}
MEDWidgetHelperSlices::MEDWidgetHelperSlices(const PresentationController * presController,
MEDCALC::MEDPresentationManager_ptr presManager, int presId,
const std::string & presName, WidgetPresentationParameters * paramW):
- MEDWidgetHelper(presController, presManager, presId, presName, paramW),
+ MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW),
_nbSlices(-1),
_sliceOrientation(MEDCALC::SLICE_ORIENTATION_DEFAULT)
{}
void MEDWidgetHelperSlices::updateWidget(bool connect)
{
- MEDWidgetHelper::updateWidget(connect);
- STDLOG("MEDWidgetHelperSlices::udpateWidget() nbSlices is " << _nbSlices);
+ MEDWidgetHelperComponent::updateWidget(connect);
_paramWidget->setNbSlices(_nbSlices);
_paramWidget->setSliceOrientation(_sliceOrientation);
// Connect combo box changes
if (connect)
{
- QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
- _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
QObject::connect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
}
{
MEDWidgetHelper::releaseWidget();
- QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
- _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
QObject::disconnect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
}
#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERSLICES_HXX_
#define SRC_MEDCALC_GUI_MEDWIDGETHELPERSLICES_HXX_
-#include "MEDWidgetHelper.hxx"
+#include "MEDWidgetHelperComponent.hxx"
class PresentationController;
-class MEDWidgetHelperSlices: public MEDWidgetHelper
+class MEDWidgetHelperSlices: public MEDWidgetHelperComponent
{
Q_OBJECT
class PresentationController;
-class MEDWidgetHelperVectorField: public MEDWidgetHelperComponent
+class MEDWidgetHelperVectorField: public MEDWidgetHelper
{
Q_OBJECT
MEDWidgetHelperVectorField(const PresentationController* presController,
MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
WidgetPresentationParameters * paramW):
- MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW)
+ MEDWidgetHelper(presController, presManager, presId, presName, paramW)
{}
-
virtual ~MEDWidgetHelperVectorField() {}
virtual std::string getPythonTag() const { return "VectorField"; }
+
};
#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_ */
from medpresentation import UpdatePointSprite
#from medpresentation import UpdateDeflectionShape
-from medpresentation import SetDefaultScaleFactor, ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins
+from medpresentation import ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins
# Console commands
import medconsole
def MakeVectorField(proxy,
viewMode=MEDCALC.VIEW_MODE_DEFAULT,
- displayedComponent=MEDCALC.DISPLAY_DEFAULT,
scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
colorMap=MEDCALC.COLOR_MAP_DEFAULT
):
# Create the presentation instance in CORBA engine
# The engine in turn creates the ParaView pipeline elements
- params = MEDCALC.VectorFieldParameters(proxy.id, displayedComponent, scalarBarRange, colorMap)
+ params = MEDCALC.VectorFieldParameters(proxy.id, scalarBarRange, colorMap)
try:
presentation_id = __manager.makeVectorField(params, viewMode)
notifyGui_addPresentation(proxy.id, presentation_id)
mids = [x[0] + 0.5*(x[1]-x[0]) for x in bb]
return mids
-# Taken from paraview.simple from CEA ParaView's version:
-def SetDefaultScaleFactor(active=None):
- """Provides a good display to the bounding box of the mesh and min / max of the field.
- This method available for filters: Warp By Vector, Glyph and Tensor Glyph"""
- if not active:
- active = GetActiveSource()
- if not active:
- return
- name = active.__class__.__name__
- if (name == 'WarpByVector' or name == 'TensorGlyph') and hasattr(active, 'ScaleFactor'):
- import math
- datainfo = active.GetProperty("Input").SMProperty.GetProxy(0).GetDataInformation()
- if not datainfo:
- active.ScaleFactor = 1.0
- return
- nbcells = datainfo.GetNumberOfCells()
- nbpoints = datainfo.GetNumberOfPoints()
- nbelem = nbcells
- if nbelem == 0:
- nbelem = nbpoints
- abounds = datainfo.GetBounds()
- volume = 1
- vol = 0
- idim = 0
- i = 0
- eps = 1.0e-38
- while i < 6 :
- vol = math.fabs( abounds[i+1] - abounds[i] )
- if vol > 0:
- idim += 1
- volume *= vol
- i += 2
- if nbelem == 0 or math.fabs(idim) < eps:
- active.ScaleFactor = 0.0
- return
- volume /= nbelem
- scalefactor = pow( volume, 1.0 / idim )
- maximum = 1.0
- property = active.GetProperty('ScaleFactor')
- domain = None
- if property.GetDomain('vector_range').__class__.__name__ == 'vtkSMArrayRangeDomain':
- domain = property.GetDomain('vector_range')
- if property.GetDomain('tensor_range').__class__.__name__ == 'vtkSMArrayRangeDomain':
- domain = property.GetDomain('tensor_range')
- if not domain is None:
- if domain.GetMaximumExists(3):
- maximum = domain.GetMaximum(3)
- if math.fabs(maximum) > eps:
- scalefactor /= maximum
- active.ScaleFactor = scalefactor
- return
- if name == 'Glyph' and hasattr(active, 'ScaleFactor') and hasattr(active, 'UseCellsCenter') and hasattr(active, 'ScaleMode'):
- import math
- scaledextent = 1.0
- property = active.GetProperty('ScaleFactor')
- bounds_domain = property.GetDomain('bounds')
- if bounds_domain.__class__.__name__ == 'vtkSMBoundsDomain':
- if bounds_domain.GetMaximumExists(0):
- scaledextent = bounds_domain.GetMaximum(0)
- usecellscenter = active.GetProperty('UseCellsCenter').GetData()
- sdomain = "cells_"
- if usecellscenter == 0:
- sdomain = "points_"
- divisor = 1.0
- scalemode_domain = active.GetProperty('ScaleMode')
- scalemode = scalemode_domain.ConvertValue(scalemode_domain.GetData())
- if scalemode == 0:
- sdomain += "scalar_range"
- domain = property.GetDomain(sdomain)
- if domain.__class__.__name__ == 'vtkSMArrayRangeDomain':
- if domain.GetMaximumExists(0):
- divisor = domain.GetMaximum(0)
- if scalemode == 1 or scalemode == 2:
- sdomain += "vector_range"
- domain = property.GetDomain(sdomain)
- if domain.__class__.__name__ == 'vtkSMArrayRangeDomain':
- if domain.GetMaximumExists(3):
- divisor = domain.GetMaximum(3)
- divisor = math.fabs(divisor)
- if divisor < 0.000000001:
- divisor = 1
- scalefactor = scaledextent / divisor
- active.ScaleFactor = scalefactor
- return
-
def GetSliceOrigins(obj, nbSlices, normal):
"""
Compute all origin points for the position of the slices.