-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a drop zone - Add a new dynamic vtkF3DDropZoneActor (co-author: @snoyer ) - Show the dropzone when no file are loaded - Remove previous behavior of showing information in the filename info - Add a test
- Loading branch information
Showing
12 changed files
with
270 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
library/VTKExtensions/Rendering/vtkF3DDropZoneActor.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "vtkF3DDropZoneActor.h" | ||
|
||
#include <vtkObjectFactory.h> | ||
#include <vtkPolyData.h> | ||
#include <vtkPolyDataMapper2D.h> | ||
#include <vtkTextMapper.h> | ||
#include <vtkTextProperty.h> | ||
#include <vtkViewport.h> | ||
|
||
vtkStandardNewMacro(vtkF3DDropZoneActor); | ||
|
||
//------------------------------------------------------------------------------ | ||
vtkF3DDropZoneActor::vtkF3DDropZoneActor() | ||
{ | ||
this->TextActor->SetMapper(this->TextMapper); | ||
vtkTextProperty* tProp = this->TextMapper->GetTextProperty(); | ||
tProp->SetFontSize(25); | ||
tProp->SetJustificationToCentered(); | ||
tProp->SetVerticalJustificationToCentered(); | ||
|
||
this->BorderMapper->SetInputData(this->BorderPolyData); | ||
this->BorderActor->SetMapper(this->BorderMapper); | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
vtkF3DDropZoneActor::~vtkF3DDropZoneActor() = default; | ||
|
||
//------------------------------------------------------------------------------ | ||
void vtkF3DDropZoneActor::ReleaseGraphicsResources(vtkWindow* win) | ||
{ | ||
this->TextActor->ReleaseGraphicsResources(win); | ||
this->BorderActor->ReleaseGraphicsResources(win); | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
int vtkF3DDropZoneActor::RenderOverlay(vtkViewport* viewport) | ||
{ | ||
int* vSize = viewport->GetSize(); | ||
|
||
// Simply position text actor in the middle | ||
this->TextMapper->SetInput(this->DropText.c_str()); | ||
this->TextActor->SetPosition(vSize[0] / 2, vSize[1] / 2); | ||
this->TextActor->RenderOverlay(viewport); | ||
|
||
if (this->BuildBorderGeometry(viewport)) | ||
{ | ||
this->BorderActor->RenderOverlay(viewport); | ||
} | ||
return 1; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
bool vtkF3DDropZoneActor::BuildBorderGeometry(vtkViewport* viewport) | ||
{ | ||
constexpr int tickWidth = 3; | ||
constexpr int tickLength = 10; | ||
|
||
int* vSize = viewport->GetSize(); | ||
if (vSize[0] == this->ComputedBorderViewportSize[0] && | ||
vSize[1] == this->ComputedBorderViewportSize[1]) | ||
{ | ||
return true; | ||
} | ||
|
||
// padding is 10% of shortest side | ||
int padding = static_cast<int>(std::min(vSize[0], vSize[1]) * 0.1); | ||
int borderW = vSize[0] - 2 * padding; | ||
int borderH = vSize[1] - 2 * padding; | ||
|
||
// number of ticks assuming spacing == tickLength | ||
int nTicksW = static_cast<int>(std::ceil(borderW / (tickLength * 2.0))); | ||
int nTicksH = static_cast<int>(std::ceil(borderH / (tickLength * 2.0))); | ||
|
||
// recompute uniform spacing | ||
double spacingW = static_cast<double>(borderW - nTicksW * tickLength) / (nTicksW - 1); | ||
double spacingH = static_cast<double>(borderH - nTicksH * tickLength) / (nTicksH - 1); | ||
|
||
vtkNew<vtkPoints> borderPoints; | ||
vtkNew<vtkCellArray> borderCells; | ||
borderPoints->SetNumberOfPoints(4 * (2 * nTicksW + 2 * nTicksH)); | ||
vtkIdType index = 0; | ||
|
||
// Draw top/bottom | ||
for (int i = 0; i < nTicksW; ++i) | ||
{ | ||
int x0 = padding + tickLength * i + spacingW * i; | ||
int x1 = x0 + tickLength; | ||
int y[2] = { padding, vSize[1] - padding }; | ||
int h[2] = { +tickWidth, -tickWidth }; | ||
for (int j = 0; j < 2; ++j) | ||
{ | ||
vtkIdType ids[4] = { index++, index++, index++, index++ }; | ||
borderPoints->SetPoint(ids[0], x0, y[j] + h[j], 0.); | ||
borderPoints->SetPoint(ids[1], x1, y[j] + h[j], 0.); | ||
borderPoints->SetPoint(ids[2], x1, y[j], 0.); | ||
borderPoints->SetPoint(ids[3], x0, y[j], 0.); | ||
borderCells->InsertNextCell(4, ids); | ||
} | ||
} | ||
|
||
// Draw left/right | ||
for (int i = 0; i < nTicksH; ++i) | ||
{ | ||
int y0 = padding + tickLength * i + spacingH * i; | ||
int y1 = y0 + tickLength; | ||
int x[2] = { padding, vSize[0] - padding }; | ||
int w[2] = { +tickWidth, -tickWidth }; | ||
for (int j = 0; j < 2; ++j) | ||
{ | ||
vtkIdType ids[4] = { index++, index++, index++, index++ }; | ||
borderPoints->SetPoint(ids[0], x[j], y0, 0.); | ||
borderPoints->SetPoint(ids[1], x[j] + w[j], y0, 0.); | ||
borderPoints->SetPoint(ids[2], x[j] + w[j], y1, 0.); | ||
borderPoints->SetPoint(ids[3], x[j], y1, 0.); | ||
borderCells->InsertNextCell(4, ids); | ||
} | ||
} | ||
|
||
this->BorderPolyData->SetPoints(borderPoints); | ||
this->BorderPolyData->SetPolys(borderCells); | ||
|
||
this->ComputedBorderViewportSize[0] = vSize[0]; | ||
this->ComputedBorderViewportSize[1] = vSize[1]; | ||
return true; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
vtkTextProperty* vtkF3DDropZoneActor::GetTextProperty() | ||
{ | ||
return this->TextMapper->GetTextProperty(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @class vtkF3DDropZoneActor | ||
* @brief A F3D dedicated drop zone actor | ||
* | ||
* This actor show a drop zone with a fixed text | ||
* in the center of the screen. The main feature | ||
* is the geometry of the dropzone that adapts to the size of | ||
* of the viewport. | ||
*/ | ||
|
||
#ifndef vtkF3DDropZoneActor_h | ||
#define vtkF3DDropZoneActor_h | ||
|
||
#include <vtkActor2D.h> | ||
|
||
#include <vtkNew.h> | ||
|
||
class vtkTextMapper; | ||
class vtkTextProperty; | ||
class vtkPolyData; | ||
class vtkPolyDataMapper2D; | ||
|
||
class vtkF3DDropZoneActor : public vtkActor2D | ||
{ | ||
public: | ||
static vtkF3DDropZoneActor* New(); | ||
vtkTypeMacro(vtkF3DDropZoneActor, vtkActor2D); | ||
|
||
/** | ||
* Set the drop text to display | ||
*/ | ||
vtkSetMacro(DropText, std::string); | ||
|
||
/** | ||
* Get the text property used to display text in this actor | ||
*/ | ||
vtkTextProperty* GetTextProperty(); | ||
|
||
/** | ||
* Release private actor graphic resources | ||
*/ | ||
void ReleaseGraphicsResources(vtkWindow*) override; | ||
|
||
/** | ||
* Render private actors overlay | ||
*/ | ||
int RenderOverlay(vtkViewport* viewport) override; | ||
|
||
protected: | ||
vtkF3DDropZoneActor(); | ||
~vtkF3DDropZoneActor() override; | ||
|
||
private: | ||
vtkF3DDropZoneActor(const vtkF3DDropZoneActor&) = delete; | ||
void operator=(const vtkF3DDropZoneActor&) = delete; | ||
|
||
/** | ||
* Build the border geometry if the size of the viewport changed | ||
* Return true on success, false otherwise | ||
*/ | ||
bool BuildBorderGeometry(vtkViewport* viewport); | ||
|
||
std::string DropText; | ||
vtkNew<vtkActor2D> TextActor; | ||
vtkNew<vtkTextMapper> TextMapper; | ||
int ComputedBorderViewportSize[2] = { -1, -1 }; | ||
vtkNew<vtkPolyData> BorderPolyData; | ||
vtkNew<vtkActor2D> BorderActor; | ||
vtkNew<vtkPolyDataMapper2D> BorderMapper; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.