Commit 0a421e4b authored by Cory Quammen's avatar Cory Quammen

Add VR style to rescale geometry

This style computes and applies a model transform matrix to apply to
all geometry in a view to scale it into the space defined by a CAVE.
parent 56c4dcb5
Pipeline #206502 failed with stage
......@@ -34,6 +34,8 @@ set(sources
vtkVRControlSliceOrientationStyle.h
vtkVRControlSlicePositionStyle.cxx
vtkVRControlSlicePositionStyle.h
vtkVRRescaleGeometryStyle.cxx
vtkVRRescaleGeometryStyle.h
vtkVRGrabPointStyle.cxx
vtkVRGrabPointStyle.h
vtkVRGrabTransformStyle.cxx
......
......@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Includes all the interaction styles:
#include "vtkVRControlSliceOrientationStyle.h"
#include "vtkVRControlSlicePositionStyle.h"
#include "vtkVRRescaleGeometryStyle.h"
#include "vtkVRGrabPointStyle.h"
#include "vtkVRGrabTransformStyle.h"
#include "vtkVRGrabWorldStyle.h"
......@@ -124,6 +125,9 @@ vtkVRInteractorStyleFactory::vtkVRInteractorStyleFactory()
// Add Wand style
this->InteractorStyleClassNames.push_back("vtkVRWandNavigationStyle");
this->InteractorStyleDescriptions.push_back("Wand Navigation");
this->InteractorStyleClassNames.push_back("vtkVRRescaleGeometryStyle");
this->InteractorStyleDescriptions.push_back("Rescale Geometry");
}
//-----------------------------------------------------------------------------
......@@ -228,6 +232,10 @@ vtkVRInteractorStyle* vtkVRInteractorStyleFactory::NewInteractorStyleFromClassNa
{
return vtkVRWandNavigationStyle::New();
}
else if (name == "vtkVRRescaleGeometryStyle")
{
return vtkVRRescaleGeometryStyle::New();
}
return nullptr;
}
......
/*=========================================================================
Program: ParaView
Module: vtkVRRescaleGeometryStyle.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 "vtkVRRescaleGeometryStyle.h"
#include "vtkBoundingBox.h"
#include "vtkObjectFactory.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxyIterator.h"
#include "vtkSMRepresentationProxy.h"
#include "vtkSMSourceProxy.h"
#include "vtkPVDataInformation.h"
#include "vtkSMRenderViewProxy.h"
#include "vtkTransform.h"
#include "vtkVRQueue.h"
struct vtkVREvent;
// ----------------------------------------------------------------------------
vtkStandardNewMacro(vtkVRRescaleGeometryStyle);
// ----------------------------------------------------------------------------
// Constructor method
vtkVRRescaleGeometryStyle::vtkVRRescaleGeometryStyle()
: Superclass()
{
this->AddButtonRole("RescaleGeometry");
}
// ----------------------------------------------------------------------------
// Destructor method
vtkVRRescaleGeometryStyle::~vtkVRRescaleGeometryStyle()
{
}
// ----------------------------------------------------------------------------
// PrintSelf() method
void vtkVRRescaleGeometryStyle::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
// ----------------------------------------------------------------------------
// HandleTracker() method
void vtkVRRescaleGeometryStyle::HandleButton(const vtkVREvent& event)
{
vtkSMRenderViewProxy* rvProxy = vtkSMRenderViewProxy::SafeDownCast(this->ControlledProxy);
if (!rvProxy)
{
vtkErrorMacro("RescaleGeometry style can only be used to affect RenderView proxies");
return;
}
std::string role = this->GetButtonRole(event.name);
if (role == "RescaleGeometry" && event.data.button.state == 1)
{
// Create a transform matrix that scales the visible geometry to unit cube
// Get all proxies under "sources" group and add them to the menu.
vtkNew<vtkSMProxyIterator> proxyIter;
proxyIter->SetModeToOneGroup();
// Loop over representation proxies in the current active server/session
// and build a bounding box from that.
vtkBoundingBox bbox;
proxyIter->SetSession(rvProxy->GetSession());
int visibleRepresentations = 0;
for (proxyIter->Begin("representations"); !proxyIter->IsAtEnd(); proxyIter->Next())
{
auto reprProxy = vtkSMRepresentationProxy::SafeDownCast(proxyIter->GetProxy());
if (!reprProxy || vtkSMPropertyHelper(reprProxy, "Visibility").GetAsInt() != 1)
{
continue;
}
vtkPVDataInformation* info = reprProxy->GetRepresentedDataInformation();
double bounds[6];
info->GetBounds(bounds);
bbox.AddBounds(bounds);
++visibleRepresentations;
}
if (visibleRepresentations == 0)
{
return;
}
double bounds[6];
bbox.GetBounds(bounds);
double center[3];
bbox.GetCenter(center);
vtkNew<vtkTransform> tform;
tform->PostMultiply();
// Transform to unit cube centered at origin
tform->Translate(-center[0], -center[1], -center[2]);
double scale = 1.0 / bbox.GetMaxLength();
tform->Scale(scale, scale, scale);
// TODO - need some way to set desired bounds
double caveCenter[3] = { 0.0, 0.0, 0.0 };
double caveLengths[3] = { 2.0, 2.0, 2.0 };
double maxCaveLength = caveLengths[0];
for (int i = 1; i < 3; ++i)
{
if (caveLengths[i] > maxCaveLength)
{
maxCaveLength = caveLengths[i];
}
}
// Now transform to the CAVE space.
tform->Scale(maxCaveLength, maxCaveLength, maxCaveLength);
tform->Translate(caveCenter[0], caveCenter[1], caveCenter[2]);
vtkNew<vtkMatrix4x4> matrix;
tform->GetMatrix(matrix);
vtkSMPropertyHelper(this->ControlledProxy, this->ControlledPropertyName).
Set(&matrix->Element[0][0], 16);
}
this->ControlledProxy->UpdateVTKObjects();
}
/*=========================================================================
Program: ParaView
Module: vtkVRRescaleGeometryStyle.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 vtkVRRescaleGeometryStyle_h
#define vtkVRRescaleGeometryStyle_h
#include "vtkNew.h"
#include "vtkVRInteractorStyle.h"
struct vtkVREvent;
/**
* Interactor style to rescale visible geometry to fit within the space
* defining a CAVE. The CAVE space is hard-coded to a 2x2x2 cube centered
* at the origin.
*
* This style responds to button events. The controlled proxy must be a RenderView,
* and the controlled property is assumed to be the ModelTransformMatrix.
*/
class vtkVRRescaleGeometryStyle : public vtkVRInteractorStyle
{
public:
static vtkVRRescaleGeometryStyle* New();
vtkTypeMacro(vtkVRRescaleGeometryStyle, vtkVRInteractorStyle);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* This style operates only on 16-element matrices.
*/
int GetControlledPropertySize() override { return 16; }
protected:
vtkVRRescaleGeometryStyle();
~vtkVRRescaleGeometryStyle() override;
void HandleButton(const vtkVREvent& event) override;
private:
vtkVRRescaleGeometryStyle(const vtkVRRescaleGeometryStyle&) = delete; // Not implemented
void operator=(const vtkVRRescaleGeometryStyle&) = delete; // Not implemented
};
#endif // vtkVRRescaleGeometryStyle_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment