Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize up direction #1536

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ f3d_test(NAME TestNRRD DATA beach.nrrd ARGS -s DEFAULT_LIGHTS)
f3d_test(NAME TestGridX DATA suzanne.ply ARGS -g --up=+X DEFAULT_LIGHTS)
f3d_test(NAME TestGridY DATA suzanne.ply ARGS -g --up=+Y DEFAULT_LIGHTS)
f3d_test(NAME TestGridZ DATA suzanne.ply ARGS -g --up=+Z DEFAULT_LIGHTS)
f3d_test(NAME TestGridUp123 DATA suzanne.ply ARGS -g --up=1,2,3 DEFAULT_LIGHTS)
f3d_test(NAME TestGridUp100 DATA suzanne.ply ARGS -g --up=1,0,0 DEFAULT_LIGHTS)
f3d_test(NAME TestGridUp000 DATA suzanne.ply ARGS -g --up=0,0,0 DEFAULT_LIGHTS)
f3d_test(NAME TestGridOptions DATA suzanne.ply ARGS -g --camera-elevation-angle=45 --grid-unit=2 --grid-subdivisions=3 DEFAULT_LIGHTS)
f3d_test(NAME TestGridAbsolute DATA f3d.vtp ARGS -g --up=-Y --camera-direction=-.5,+1,+1 --grid-absolute DEFAULT_LIGHTS)
f3d_test(NAME TestGridClipping DATA offset-flat-box.glb ARGS -g --grid-absolute --camera-position=70,120,350 DEFAULT_LIGHTS)
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestGridUp000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestGridUp100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestGridUp123.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestGridX.png
Meakk marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions vtkext/private/module/Testing/TestF3DOpenGLGridMapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,8 @@ int TestF3DOpenGLGridMapper(int argc, char* argv[])
/* `OriginOffset` offset is only for drawing the axes within the actor,
* it should not affect the actual bounding box */

mapper->SetUpIndex(0);
if (!CheckBounds("YZ with offset", mapper, -safeMargin, +safeMargin, -r, +r, -r, +r))
return EXIT_FAILURE;

mapper->SetUpIndex(1);
if (!CheckBounds("XZ with offset", mapper, -r, +r, -safeMargin, +safeMargin, -r, +r))
return EXIT_FAILURE;

mapper->SetUpIndex(2);
if (!CheckBounds("XY with offset", mapper, -r, +r, -r, +r, -safeMargin, +safeMargin))
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
Expand Down
44 changes: 10 additions & 34 deletions vtkext/private/module/vtkF3DOpenGLGridMapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void vtkF3DOpenGLGridMapper::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "FadeDistance: " << this->FadeDistance << "\n";
os << indent << "UnitSquare: " << this->UnitSquare << "\n";
os << indent << "Subdivisions: " << this->Subdivisions << "\n";
os << indent << "UpIndex: " << this->UpIndex << "\n";
}

//----------------------------------------------------------------------------
Expand All @@ -40,9 +39,6 @@ void vtkF3DOpenGLGridMapper::ReplaceShaderValues(
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();

const std::string axes3d = this->UpIndex == 0 ? "zyx" : this->UpIndex == 1 ? "xzy" : "xyz";
const std::string axes2d = this->UpIndex == 0 ? "zy" : this->UpIndex == 1 ? "xz" : "xy";

// clang-format off
vtkShaderProgram::Substitute(VSSource, "//VTK::PositionVC::Dec",
"uniform vec3 originOffset;\n"
Expand All @@ -52,8 +48,8 @@ void vtkF3DOpenGLGridMapper::ReplaceShaderValues(
);
vtkShaderProgram::Substitute(VSSource, "//VTK::PositionVC::Impl",
"gridCoord = vertexMC.xy * fadeDist;\n"
"gridOffset = originOffset." + axes2d + ";\n"
"gl_Position = MCDCMatrix * vec4(vertexMC." + axes3d + " * fadeDist, 1.0);\n"
"gridOffset = originOffset.xz;\n"
"gl_Position = MCDCMatrix * vec4(vertexMC.xzy * fadeDist, 1.0);\n"
);

vtkShaderProgram::Substitute(FSSource, "//VTK::CustomUniforms::Dec",
Expand Down Expand Up @@ -157,26 +153,8 @@ void vtkF3DOpenGLGridMapper::SetMapperShaderParameters(
cellBO.Program->SetUniformf("gridLineWidth", 0.6);
cellBO.Program->SetUniformf("minorOpacity", 0.5);
cellBO.Program->SetUniformf("lineAntialias", 1);

const float xColor[4] = { 1, 0, 0, 1 };
const float yColor[4] = { 0, 1, 0, 1 };
const float zColor[4] = { 0, 0, 1, 1 };
switch (this->UpIndex)
{
case 0:
cellBO.Program->SetUniform4f("axis1Color", zColor);
cellBO.Program->SetUniform4f("axis2Color", yColor);
break;
case 1:
cellBO.Program->SetUniform4f("axis1Color", xColor);
cellBO.Program->SetUniform4f("axis2Color", zColor);
break;
case 2:
default:
cellBO.Program->SetUniform4f("axis1Color", xColor);
cellBO.Program->SetUniform4f("axis2Color", yColor);
break;
}
cellBO.Program->SetUniform4f("axis1Color", this->Axis1Color);
cellBO.Program->SetUniform4f("axis2Color", this->Axis2Color);
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -210,14 +188,12 @@ void vtkF3DOpenGLGridMapper::BuildBufferObjects(vtkRenderer* ren, vtkActor* vtkN
//-----------------------------------------------------------------------------
double* vtkF3DOpenGLGridMapper::GetBounds()
{
double r[3] = { this->FadeDistance, this->FadeDistance, this->FadeDistance };
r[this->UpIndex] = 1e-4;
this->Bounds[0] = -r[0];
this->Bounds[1] = +r[0];
this->Bounds[2] = -r[1];
this->Bounds[3] = +r[1];
this->Bounds[4] = -r[2];
this->Bounds[5] = +r[2];
this->Bounds[0] = -this->FadeDistance;
this->Bounds[1] = +this->FadeDistance;
this->Bounds[2] = -1e-4;
this->Bounds[3] = +1e-4;
this->Bounds[4] = -this->FadeDistance;
this->Bounds[5] = +this->FadeDistance;
return this->Bounds;
}

Expand Down
12 changes: 9 additions & 3 deletions vtkext/private/module/vtkF3DOpenGLGridMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ class vtkF3DOpenGLGridMapper : public vtkOpenGLPolyDataMapper
vtkSetMacro(Subdivisions, int);

/**
* Set the up vector index (X, Y, Z axis respectively).
* Set the color (RGBA) of the first axes
*/
vtkSetClampMacro(UpIndex, int, 0, 2);
vtkSetVector4Macro(Axis1Color, float);

/**
* Set the color (RGBA) of the second axes
*/
vtkSetVector4Macro(Axis2Color, float);

using vtkOpenGLPolyDataMapper::GetBounds;
double* GetBounds() override;
Expand Down Expand Up @@ -68,7 +73,8 @@ class vtkF3DOpenGLGridMapper : public vtkOpenGLPolyDataMapper
double FadeDistance = 10.0;
double UnitSquare = 1.0;
int Subdivisions = 10;
int UpIndex = 1;
float Axis1Color[4] = { 0.0, 0.0, 0.0, 1.0 };
float Axis2Color[4] = { 0.0, 0.0, 0.0, 1.0 };
};

#endif
Loading