Commit 13e149b1 authored by Maire Nicolas's avatar Maire Nicolas

Rajout de presets dans clippingPresets

parent fe9839c3
...@@ -302,6 +302,50 @@ void Clipping::slot_pushButton_applyClippingPreset() ...@@ -302,6 +302,50 @@ void Clipping::slot_pushButton_applyClippingPreset()
preset = Utils::ClippingPreset::CreateCubePreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, facing); preset = Utils::ClippingPreset::CreateCubePreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, facing);
} }
break; break;
case 2 : // Tube
{
using namespace CGoGN::Utils::QT;
double centerX = (double)m_bb.center()[0];
double centerY = (double)m_bb.center()[1];
double centerZ = (double)m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75;
int axis = 0;
int precision = 1;
bool facing = false;
if (inputValues(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
VarSlider(0, 2, axis, "Axis",
VarSlider(1, 30, precision, "Precision",
VarBool(facing, "Facing"
))))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateTubePreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, axis, precision, facing);
}
break;
case 3 : // Molecule
{
using namespace CGoGN::Utils::QT;
double centerX = (double)m_bb.center()[0];
double centerY = (double)m_bb.center()[1];
double centerZ = (double)m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75;
double atomsRadiuses = (double)m_bb.maxSize()*0.25;
bool orClipping = true;
if (inputValues(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
VarDbl(atomsRadiuses - 100.0, atomsRadiuses + 100.0, atomsRadiuses, "Atoms radiuses",
VarBool(orClipping, "OR clipping mode"
)))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateMoleculePreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, atomsRadiuses, orClipping);
}
break;
} }
std::vector<unsigned int> planesIds; std::vector<unsigned int> planesIds;
std::vector<unsigned int> spheresIds; std::vector<unsigned int> spheresIds;
...@@ -340,6 +384,8 @@ void Clipping::slot_pushButton_applyClippingPreset() ...@@ -340,6 +384,8 @@ void Clipping::slot_pushButton_applyClippingPreset()
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]); Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]);
pickable->translate(m_shader->getClipSphereParamsCenter(spheresIds[i])); pickable->translate(m_shader->getClipSphereParamsCenter(spheresIds[i]));
pickable->scale(m_shader->getClipSphereParamsRadius(spheresIds[i])); pickable->scale(m_shader->getClipSphereParamsRadius(spheresIds[i]));
m_pickableSpheres.push_back(pickable);
} }
// Update shader sources edits // Update shader sources edits
...@@ -452,6 +498,8 @@ void Clipping::initGUI() ...@@ -452,6 +498,8 @@ void Clipping::initGUI()
dock.comboBox_ClippingPresets->addItem("Dual Planes"); dock.comboBox_ClippingPresets->addItem("Dual Planes");
dock.comboBox_ClippingPresets->addItem("Cube"); dock.comboBox_ClippingPresets->addItem("Cube");
dock.comboBox_ClippingPresets->addItem("Tube");
dock.comboBox_ClippingPresets->addItem("Molecule");
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "Utils/clippingShader.h" #include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include <vector> #include <vector>
#include <cmath>
namespace CGoGN namespace CGoGN
{ {
...@@ -53,7 +54,7 @@ public : ...@@ -53,7 +54,7 @@ public :
/** /**
* public static constructor * public static constructor
* @param center center between planes * @param center center between planes
* @param distance distance between planes * @param size distance between planes
* @param axis axis on which planes are aligned (0 for x, 1 for y, 2 for z) * @param axis axis on which planes are aligned (0 for x, 1 for y, 2 for z)
* @param facing true means having facing planes * @param facing true means having facing planes
*/ */
...@@ -62,11 +63,30 @@ public : ...@@ -62,11 +63,30 @@ public :
/** /**
* public static constructor * public static constructor
* @param center center between planes * @param center center between planes
* @param distance distance between planes * @param size distance between planes
* @param facing true means having facing planes * @param facing true means having facing planes
*/ */
static ClippingPreset* CreateCubePreset(Geom::Vec3f center, float size, bool facing); static ClippingPreset* CreateCubePreset(Geom::Vec3f center, float size, bool facing);
/**
* public static constructor
* @param center center of the tube
* @param size tube diameter
* @param axis axis of the tube (0 for x, 1 for y, 2 for z)
* @param precision planes count used to build tube
* @param facing true means an outer tube, false an inner tube
*/
static ClippingPreset* CreateTubePreset(Geom::Vec3f center, float size, int axis, int precision, bool facing);
/**
* public static constructor
* @param center center of molecule
* @param size molecule size
* @param atomsRadiuses radiuses of atoms
* @param orClipping set it to true for OR clipping mode
*/
static ClippingPreset* CreateMoleculePreset(Geom::Vec3f center, float size, float atomsRadiuses, bool orClipping);
private : private :
/// private constructor (used by public static constructors) /// private constructor (used by public static constructors)
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <cmath>
namespace CGoGN namespace CGoGN
{ {
......
...@@ -49,18 +49,20 @@ ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float ...@@ -49,18 +49,20 @@ ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float
{ {
ClippingPreset *preset = new ClippingPreset; ClippingPreset *preset = new ClippingPreset;
// Axis on which planes will be aligned // Correct axis if necessary
if ((axis < 0) || (axis > 2)) if ((axis < 0) || (axis > 2))
axis = 0; axis = 0;
// Axis on which planes will be aligned
Geom::Vec3f positDir (0.0f, 0.0f, 0.0f); Geom::Vec3f positDir (0.0f, 0.0f, 0.0f);
positDir[axis] = 1.0f; positDir[axis] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f); Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[axis] = -1.0f; negDir[axis] = -1.0f;
// Facing of planes // Facing of planes
float side = 1.0; float side = 1.0f;
if (facing) if (facing)
side = -1.0; side = -1.0f;
// Add planes to preset // Add planes to preset
preset->addClipPlane(positDir, center + positDir*(size / 2.0f)*(side)); preset->addClipPlane(positDir, center + positDir*(size / 2.0f)*(side));
...@@ -88,9 +90,9 @@ ClippingPreset* ClippingPreset::CreateCubePreset(Geom::Vec3f center, float size, ...@@ -88,9 +90,9 @@ ClippingPreset* ClippingPreset::CreateCubePreset(Geom::Vec3f center, float size,
Geom::Vec3f zAxisNeg = Geom::Vec3f (0.0f, 0.0f, -1.0f); Geom::Vec3f zAxisNeg = Geom::Vec3f (0.0f, 0.0f, -1.0f);
// Facing of planes // Facing of planes
float side = 1.0; float side = 1.0f;
if (facing) if (facing)
side = -1.0; side = -1.0f;
// Add planes to preset // Add planes to preset
preset->addClipPlane(xAxisPos, center + xAxisPos*(size / 2.0f)*(side)); preset->addClipPlane(xAxisPos, center + xAxisPos*(size / 2.0f)*(side));
...@@ -109,6 +111,66 @@ ClippingPreset* ClippingPreset::CreateCubePreset(Geom::Vec3f center, float size, ...@@ -109,6 +111,66 @@ ClippingPreset* ClippingPreset::CreateCubePreset(Geom::Vec3f center, float size,
return preset; return preset;
} }
ClippingPreset* ClippingPreset::CreateTubePreset(Geom::Vec3f center, float size, int axis, int precision, bool facing)
{
ClippingPreset *preset = new ClippingPreset;
// Correct axis if necessary
if ((axis < 0) || (axis > 2))
axis = 0;
// Correct precision if necessary
if (precision < 1)
precision = 1;
// Facing of planes
float side = 1.0f;
if (facing)
side = -1.0f;
// Add planes to preset
Geom::Vec3f direction (0.0, 0.0, 0.0);
float dAngle = 2.0f * M_PI / precision;
for (int i = 0; i < precision; i++)
{
direction[(axis + 1) % 3] = cos(i*dAngle);
direction[(axis + 2) % 3] = sin(i*dAngle);
preset->addClipPlane(direction, center + direction*(size / 2.0f)*(side));
}
// Set clipping mode
ClippingShader::clippingMode clipMode = ClippingShader::CLIPPING_MODE_AND;
if (facing)
clipMode = ClippingShader::CLIPPING_MODE_OR;
preset->setClippingMode(clipMode);
return preset;
}
ClippingPreset* ClippingPreset::CreateMoleculePreset(Geom::Vec3f center, float size, float atomsRadiuses, bool orClipping)
{
ClippingPreset *preset = new ClippingPreset;
// Add spheres to preset on each axis
for (int i = 0; i < 3; i++)
{
Geom::Vec3f positDir (0.0f, 0.0f, 0.0f);
positDir[i] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[i] = -1.0f;
preset->addClipSphere(center + positDir*(size / 2.0f), atomsRadiuses);
preset->addClipSphere(center + negDir*(size / 2.0f), atomsRadiuses);
}
// Set clipping mode
ClippingShader::clippingMode clipMode = ClippingShader::CLIPPING_MODE_AND;
if (orClipping)
clipMode = ClippingShader::CLIPPING_MODE_OR;
preset->setClippingMode(clipMode);
return preset;
}
ClippingPreset::ClippingPreset(): ClippingPreset::ClippingPreset():
m_clipMode (ClippingShader::CLIPPING_MODE_AND) m_clipMode (ClippingShader::CLIPPING_MODE_AND)
{ {
......
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