Commit ecd9185a authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Updates to change-of-basis support for grid axes.

The grid axes now works with change-of-basis matrix. We now use a
behavior to setup axis titles, and such other MantId specific
customizations. While this is not through, this lays the ground work to
start removing explicit code in the rendering pipeline to handle such
meta-data and instead rely on the pqModelTransformSupportBehavior to
setup it correctly.
parent 3e7790b0
......@@ -35,35 +35,15 @@
#include <string>
#include <vector>
class vtkSMMultiSliceViewProxy::vtkInternals
{
public:
std::pair<bool, std::string> AxisLabels[3];
bool AxisLabelsUpdated;
vtkInternals() : AxisLabelsUpdated(false)
{
}
};
vtkStandardNewMacro(vtkSMMultiSliceViewProxy);
//----------------------------------------------------------------------------
vtkSMMultiSliceViewProxy::vtkSMMultiSliceViewProxy()
: Internals(new vtkSMMultiSliceViewProxy::vtkInternals())
{
}
//----------------------------------------------------------------------------
vtkSMMultiSliceViewProxy::~vtkSMMultiSliceViewProxy()
{
delete this->Internals;
this->Internals = NULL;
}
//----------------------------------------------------------------------------
void vtkSMMultiSliceViewProxy::PostUpdateData()
{
this->Internals->AxisLabelsUpdated = false;
this->Superclass::PostUpdateData();
}
//----------------------------------------------------------------------------
......@@ -77,54 +57,6 @@ void vtkSMMultiSliceViewProxy::GetDataBounds(double bounds[6])
}
}
//----------------------------------------------------------------------------
const char* vtkSMMultiSliceViewProxy::GetAxisLabel(int axis)
{
if (axis < 0 || axis > 2)
{
vtkErrorMacro("Invalid axis: " << axis);
return NULL;
}
if (this->Internals->AxisLabelsUpdated == false)
{
vtkClientServerStream stream;
stream << vtkClientServerStream::Invoke
<< VTKOBJECT(this)
<< "GetAxisLabels"
<< vtkClientServerStream::End;
this->ExecuteStream(stream, false, vtkPVSession::DATA_SERVER_ROOT);
stream.Reset();
vtkClientServerStream result = this->GetLastResult(vtkPVSession::DATA_SERVER_ROOT);
if (result.GetArgument(0, 0, &stream))
{
for (int cc=0; cc < 3; cc++)
{
bool valid;
std::string name;
if (stream.GetArgument(0, 2*cc, &valid) && stream.GetArgument(0, 2*cc+1, &name))
{
this->Internals->AxisLabels[cc].first = valid;
this->Internals->AxisLabels[cc].second = name;
}
else
{
vtkErrorMacro("Invalid reply received for axis "<< cc);
this->Internals->AxisLabels[cc].first = false;
}
}
}
else
{
vtkErrorMacro("Invalid reply received!!");
}
this->Internals->AxisLabelsUpdated = true;
}
return this->Internals->AxisLabels[axis].first?
this->Internals->AxisLabels[axis].second.c_str() : NULL;
}
//----------------------------------------------------------------------------
const char* vtkSMMultiSliceViewProxy::GetRepresentationType(
vtkSMSourceProxy* producer, int outputPort)
......
......@@ -49,11 +49,6 @@ public:
virtual const char* GetRepresentationType(
vtkSMSourceProxy* producer, int outputPort);
// Description:
// Access the axis label (0: xaxis, 1: yaxis, 2: zaxis).
// Returns NULL if no custom label was specified.
const char* GetAxisLabel(int axis);
// Description:
// Fetchs data bounds from the client-side object. We simply fetch the
// client-side data bounds since vtkPVMultiSliceView ensures that they are
......@@ -73,10 +68,6 @@ protected:
vtkSMMultiSliceViewProxy();
~vtkSMMultiSliceViewProxy();
// Overridden to collect information from server-side about data-bounds and
// axis labels.
virtual void PostUpdateData();
// Description:
// Use the center of the source to initialize the view with three orthogonal
// slices in x, y, z.
......
......@@ -7543,6 +7543,18 @@
argument_is_array="1"
panel_visibility="never">
</DoubleVectorProperty>
<StringVectorProperty name="XTitle"
number_of_elements="1"
default_values="X"
panel_visibility="never" />
<StringVectorProperty name="YTitle"
number_of_elements="1"
default_values="Y"
panel_visibility="never" />
<StringVectorProperty name="ZTitle"
number_of_elements="1"
default_values="Z"
panel_visibility="never" />
</MultiSliceViewProxy>
<!-- ================================================================== -->
......
......@@ -130,6 +130,7 @@ public:
uAxisTitle->SetNumberOfComponents(1);
uAxisTitle->SetNumberOfTuples(1);
uAxisTitle->SetValue(0, utitle);
uAxisTitle->SetComponentName(0, utitle);
dataObject->GetFieldData()->AddArray(uAxisTitle.GetPointer());
}
if (vtitle)
......@@ -139,6 +140,7 @@ public:
vAxisTitle->SetNumberOfComponents(1);
vAxisTitle->SetNumberOfTuples(1);
vAxisTitle->SetValue(0, vtitle);
vAxisTitle->SetComponentName(0, vtitle);
dataObject->GetFieldData()->AddArray(vAxisTitle.GetPointer());
}
if (wtitle)
......@@ -148,6 +150,7 @@ public:
wAxisTitle->SetNumberOfComponents(1);
wAxisTitle->SetNumberOfTuples(1);
wAxisTitle->SetValue(0, wtitle);
wAxisTitle->SetComponentName(0, wtitle);
dataObject->GetFieldData()->AddArray(wAxisTitle.GetPointer());
}
return (utitle || vtitle || wtitle);
......
......@@ -3,11 +3,35 @@ SET(PLUGIN_VERSION "1.0")
include_directories(${VTK_INCLUDE_DIRS})
ADD_PARAVIEW_PLUGIN(NonOrthogonalSource "1.0"
SERVER_MANAGER_XML vtkNonOrthogonalSource.xml
SERVER_MANAGER_SOURCES
vtkShearedWaveletSource.cxx
set(sources)
if(PARAVIEW_BUILD_QT_GUI)
if(PARAVIEW_QT_VERSION VERSION_GREATER "4")
qt5_wrap_cpp(MOC_SRCS pqNonOrthogonalAutoStart.h)
else()
qt4_wrap_cpp(MOC_SRCS pqNonOrthogonalAutoStart.h)
endif()
add_paraview_auto_start(IFACES IFACE_SRCS
CLASS_NAME pqNonOrthogonalAutoStart
STARTUP startup
SHUTDOWN shutdown)
list(APPEND sources
pqNonOrthogonalAutoStart.cxx
${MOC_SRCS}
${IFACE_SRCS})
endif()
add_paraview_plugin(NonOrthogonalSource "1.0"
SERVER_MANAGER_XML
vtkNonOrthogonalSource.xml
SERVER_MANAGER_SOURCES
vtkShearedWaveletSource.cxx
GUI_INTERFACES ${IFACES}
SOURCES ${sources}
)
if (PARAVIEW_BUILD_QT_GUI)
target_link_libraries(NonOrthogonalSource LINK_PRIVATE pqApplicationComponents)
endif()
if(BUILD_TESTING)
add_subdirectory(Testing)
......
/*=========================================================================
Program: ParaView
Module: pqNonOrthogonalAutoStart.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqNonOrthogonalAutoStart.h"
#include "pqModelTransformSupportBehavior.h"
//-----------------------------------------------------------------------------
pqNonOrthogonalAutoStart::pqNonOrthogonalAutoStart(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqNonOrthogonalAutoStart::~pqNonOrthogonalAutoStart()
{
}
//-----------------------------------------------------------------------------
void pqNonOrthogonalAutoStart::startup()
{
new pqModelTransformSupportBehavior(this);
}
//-----------------------------------------------------------------------------
void pqNonOrthogonalAutoStart::shutdown()
{
}
/*=========================================================================
Program: ParaView
Module: pqNonOrthogonalAutoStart.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef __pqNonOrthogonalAutoStart_h
#define __pqNonOrthogonalAutoStart_h
#include <QObject>
class pqNonOrthogonalAutoStart : public QObject
{
Q_OBJECT
typedef QObject Superclass;
public:
pqNonOrthogonalAutoStart(QObject* parent=0);
virtual ~pqNonOrthogonalAutoStart();
void startup();
void shutdown();
private:
Q_DISABLE_COPY(pqNonOrthogonalAutoStart)
};
#endif
/*=========================================================================
Program: ParaView
Module: pqSetupModelTransformBehavior.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef __pqSetupModelTransformBehavior_h
#define __pqSetupModelTransformBehavior_h
#include <QObject>
class VTK_EXPORT pqSetupModelTransformBehavior : public QObject
{
Q_OBJECT
typedef QObject Superclass;
public:
pqSetupModelTransformBehavior(QObject* parent=0);
virtual ~pqSetupModelTransformBehavior();
private:
Q_DISABLE_COPY(pqSetupModelTransformBehavior)
};
#endif
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy name="ShearedWavelet" class="vtkShearedWaveletSource">
<SourceProxy name="ShearedWavelet" label="Sheared Wavelet" class="vtkShearedWaveletSource">
<DoubleVectorProperty
name="U"
command="SetBasisU"
......
......@@ -166,6 +166,8 @@ set (Module_SRCS
pqManagePluginsReaction.h
pqMasterOnlyReaction.cxx
pqMasterOnlyReaction.h
pqModelTransformSupportBehavior.cxx
pqModelTransformSupportBehavior.h
pqObjectPickingBehavior.cxx
pqObjectPickingBehavior.h
pqOpacityTableModel.cxx
......@@ -338,6 +340,7 @@ set (Module_MOC_HDRS
pqManageLinksReaction.h
pqManagePluginsReaction.h
pqMasterOnlyReaction.h
pqModelTransformSupportBehavior.h
pqObjectPickingBehavior.h
pqOpacityTableModel.h
pqParaViewBehaviors.h
......
/*=========================================================================
Program: ParaView
Module: pqModelTransformSupportBehavior.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqModelTransformSupportBehavior.h"
#include "pqApplicationCore.h"
#include "pqDataRepresentation.h"
#include "pqPipelineSource.h"
#include "pqServerManagerModel.h"
#include "pqView.h"
#include "vtkPVArrayInformation.h"
#include "vtkPVDataInformation.h"
#include "vtkSMSourceProxy.h"
#include "vtkDataObject.h"
#include "vtkTuple.h"
#include "vtkSMPropertyHelper.h"
#include <QtDebug>
namespace
{
static vtkSMSourceProxy* FindVisibleProducerWithChangeOfBasisMatrix(pqView* view)
{
foreach (pqRepresentation* repr, view->getRepresentations())
{
pqDataRepresentation* drepr = qobject_cast<pqDataRepresentation*>(repr);
if (!drepr || !drepr->isVisible())
{
continue;
}
vtkPVDataInformation* info = drepr->getInputDataInformation();
vtkPVArrayInformation* cobm = info->GetArrayInformation(
"ChangeOfBasisMatrix", vtkDataObject::FIELD);
vtkPVArrayInformation* bbimc = cobm ? info->GetArrayInformation(
"BoundingBoxInModelCoordinates", vtkDataObject::FIELD) : NULL;
if (cobm && bbimc)
{
return vtkSMSourceProxy::SafeDownCast(drepr->getInput()->getProxy());
}
}
return NULL;
}
}
//-----------------------------------------------------------------------------
pqModelTransformSupportBehavior::pqModelTransformSupportBehavior(QObject* parentObject)
: Superclass(parentObject)
{
pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
this->connect(smmodel, SIGNAL(viewAdded(pqView*)), SLOT(viewAdded(pqView*)));
foreach (pqView* view, smmodel->findItems<pqView*>())
{
this->viewAdded(view);
}
}
//-----------------------------------------------------------------------------
pqModelTransformSupportBehavior::~pqModelTransformSupportBehavior()
{
}
//-----------------------------------------------------------------------------
void pqModelTransformSupportBehavior::viewAdded(pqView* view)
{
if (view)
{
this->connect(view, SIGNAL(updateDataEvent()), SLOT(viewUpdated()));
}
}
//-----------------------------------------------------------------------------
void pqModelTransformSupportBehavior::viewUpdated()
{
pqView* view = qobject_cast<pqView*>(this->sender());
Q_ASSERT(view);
// Check if there is any data source visible in the view that has a
// ChangeOfBasisMatrix and BoundingBoxInModelCoordinates specified.
if (vtkSMSourceProxy* producer = FindVisibleProducerWithChangeOfBasisMatrix(view))
{
this->enableModelTransform(view, producer);
}
else
{
this->disableModelTransform(view);
}
}
//-----------------------------------------------------------------------------
void pqModelTransformSupportBehavior::enableModelTransform(
pqView* view, vtkSMSourceProxy* producer)
{
bool are_titles_valid;
vtkTuple<vtkStdString, 3> titles = this->getAxisTitles(producer, 0, &are_titles_valid);
if (vtkSMProxy* gridAxes3DActor = vtkSMPropertyHelper(
view->getProxy(), "GridActor", /*quiet*/ true).GetAsProxy())
{
vtkSMPropertyHelper(gridAxes3DActor, "UseModelTransform").Set(1);
vtkTuple<double, 16> cobm = this->getChangeOfBasisMatrix(producer);
vtkTuple<double, 6> bounds = this->getBoundingBoxInModelCoordinates(producer);
vtkSMPropertyHelper(gridAxes3DActor, "ModelTransformMatrix").Set(cobm.GetData(), 16);
vtkSMPropertyHelper(gridAxes3DActor, "ModelBounds").Set(bounds.GetData(), 6);
if (are_titles_valid)
{
vtkSMPropertyHelper(gridAxes3DActor, "XTitle").Set(titles[0].c_str());
vtkSMPropertyHelper(gridAxes3DActor, "YTitle").Set(titles[1].c_str());
vtkSMPropertyHelper(gridAxes3DActor, "ZTitle").Set(titles[2].c_str());
}
gridAxes3DActor->UpdateVTKObjects();
}
if (are_titles_valid)
{
vtkSMProxy* viewProxy = view->getProxy();
vtkSMPropertyHelper(viewProxy, "XTitle", /*quiet*/true).Set(titles[0].c_str());
vtkSMPropertyHelper(viewProxy, "YTitle", /*quiet*/true).Set(titles[1].c_str());
vtkSMPropertyHelper(viewProxy, "ZTitle", /*quiet*/true).Set(titles[2].c_str());
viewProxy->UpdateVTKObjects();
}
}
//-----------------------------------------------------------------------------
void pqModelTransformSupportBehavior::disableModelTransform(pqView* view)
{
if (vtkSMProxy* gridAxes3DActor = vtkSMPropertyHelper(
view->getProxy(), "GridActor", /*quiet*/ true).GetAsProxy())
{
vtkSMPropertyHelper helper(gridAxes3DActor, "UseModelTransform");
if (helper.GetAsInt() != 0)
{
helper.Set(0);
gridAxes3DActor->UpdateVTKObjects();
}
}
}
//-----------------------------------------------------------------------------
template<class T, int size>
vtkTuple<T, size> GetValues(
const char* aname, vtkSMSourceProxy* producer, int port, bool *pisvalid)
{
bool dummy;
pisvalid = pisvalid? pisvalid : &dummy;
*pisvalid = false;
vtkTuple<T, size> value;
vtkPVDataInformation* dinfo = producer->GetDataInformation(port);
if (vtkPVArrayInformation* ainfo =
(dinfo? dinfo->GetArrayInformation(aname, vtkDataObject::FIELD) : NULL))
{
if (ainfo->GetNumberOfComponents() == size)
{
*pisvalid = true;
for (int cc=0; cc < size; cc++)
{
value[cc] = ainfo->GetComponentRange(cc)[0];
}
}
}
return value;
}
//-----------------------------------------------------------------------------
vtkTuple<double, 16> pqModelTransformSupportBehavior::getChangeOfBasisMatrix(
vtkSMSourceProxy* producer, int port, bool* pisvalid)
{
return GetValues<double, 16>("ChangeOfBasisMatrix", producer, port, pisvalid);
}
//-----------------------------------------------------------------------------
vtkTuple<double, 6> pqModelTransformSupportBehavior::getBoundingBoxInModelCoordinates(
vtkSMSourceProxy* producer, int port, bool* pisvalid)
{
return GetValues<double, 6>("BoundingBoxInModelCoordinates", producer, port, pisvalid);
}
//-----------------------------------------------------------------------------
vtkTuple<vtkStdString, 3> pqModelTransformSupportBehavior::getAxisTitles(
vtkSMSourceProxy* producer, int port, bool* pisvalid)
{