Commit 415c8ff3 authored by untereiner's avatar untereiner

Merge cgogn:~maire/CGoGN

parents 54bf6e17 13e149b1
......@@ -25,6 +25,36 @@
#include "clipping.h"
#include "Utils/static_assert.h"
/*******************************************************************************
* MISCELLANOUS
*******************************************************************************/
void computeBasisFromVector(const Geom::Vec3f& vec1, Geom::Vec3f& vec2, Geom::Vec3f& vec3)
{
const float epsilon = 0.0001f;
// Check if the given vector length is acceptable
if (vec1.norm() < epsilon)
return;
// First take a non colinear second vector to cross product with vec1
// (by default (0.0, 0.0, 1.0)
Geom::Vec3f tempVec (0.0, 0.0, 1.0);
// Construct second vector, check other vectors non colinearity at the same time
vec2 = vec1 ^ tempVec;
float sinAngle = vec2.norm() / (vec1.norm() + tempVec.norm());
if (sinAngle < epsilon) // f:x->sin(x) ~ f:x->x when x ~ 0
{
tempVec = Geom::Vec3f (1.0, 0.0, 0.0);
vec2 = vec1 ^ tempVec;
}
// Get third vector
vec3 = vec1 ^ vec2;
}
/*******************************************************************************
* SLOTS
*******************************************************************************/
......@@ -77,13 +107,14 @@ void Clipping::slot_explodTopoPhi3(double c)
void Clipping::slot_pushButton_addPlane()
{
// Create clipping and pickable objects
int newPlaneId = m_shader->addClipPlane();
unsigned int newPlaneId = m_shader->addClipPlane();
Utils::Pickable* pickable = new Utils::Pickable(m_planeDrawable, newPlaneId);
m_pickablePlanes.push_back(pickable);
// Set params
m_shader->setClipPlaneParamsOrigin(newPlaneId, m_bb.center());
pickable->translate(m_bb.center());
pickable->scale(Geom::Vec3f(m_bb.maxSize()*0.5));
// Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
......@@ -114,15 +145,15 @@ void Clipping::slot_pushButton_changePlanesColor()
void Clipping::slot_pushButton_addSphere()
{
// Create clipping and pickable objects
int newSphereId = m_shader->addClipSphere();
unsigned int newSphereId = m_shader->addClipSphere();
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, newSphereId);
m_pickableSpheres.push_back(pickable);
// Set params
m_shader->setClipSphereParamsCenter(newSphereId, m_bb.center());
m_shader->setClipSphereParamsRadius(newSphereId, (m_bb.maxSize())*1.0);
m_shader->setClipSphereParamsRadius(newSphereId, (m_bb.maxSize())*0.5);
pickable->translate(m_bb.center());
pickable->scale(Geom::Vec3f(m_bb.maxSize()*1.0));
pickable->scale(Geom::Vec3f(m_bb.maxSize()*0.5));
// Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
......@@ -152,7 +183,7 @@ void Clipping::slot_pushButton_changeSpheresColor()
void Clipping::slot_doubleSpinBox_ColorAttenuationFactor(double c)
{
m_shader->setClipColorAttenuationFactor((float)c);
m_shader->setClipColorAttenuationFactorAbsolute((float)c);
updateGL();
}
......@@ -226,6 +257,152 @@ void Clipping::slot_pushButton_deleteSelectedObject()
}
}
void Clipping::slot_pushButton_applyClippingPreset()
{
// Create and apply preset
Utils::ClippingPreset *preset = NULL;
switch (dock.comboBox_ClippingPresets->currentIndex())
{
case 0 : // Dual planes
{
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;
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",
VarBool(facing, "Facing"
)))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, axis, facing);
}
break;
case 1 : // Cube
{
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;
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",
VarBool(facing, "Facing"
))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateCubePreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, facing);
}
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> spheresIds;
preset->apply(m_shader, &planesIds, &spheresIds);
delete preset;
// Cleanup of pickables before adding new ones
m_lastPickedObject = NULL;
for (size_t i = 0; i < m_pickablePlanes.size(); i++)
delete m_pickablePlanes[i];
m_pickablePlanes.resize(0);
for (size_t i = 0; i < m_pickableSpheres.size(); i++)
delete m_pickableSpheres[i];
m_pickableSpheres.resize(0);
// Add new pickable objects
for (size_t i = 0; i < planesIds.size(); i++)
{
Utils::Pickable* pickable = new Utils::Pickable(m_planeDrawable, planesIds[i]);
pickable->translate(m_shader->getClipPlaneParamsOrigin(planesIds[i]));
Geom::Vec3f vec1, vec2, vec3;
vec1 = m_shader->getClipPlaneParamsNormal(planesIds[i]);
computeBasisFromVector(vec1, vec2, vec3);
glm::mat4& transfoMat = pickable->transfo();
for (int i = 0; i < 3; i++)
{
transfoMat[0][i] = vec2[i];
transfoMat[1][i] = vec3[i];
transfoMat[2][i] = vec1[i];
}
m_pickablePlanes.push_back(pickable);
}
for (size_t i = 0; i < spheresIds.size(); i++)
{
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]);
pickable->translate(m_shader->getClipSphereParamsCenter(spheresIds[i]));
pickable->scale(m_shader->getClipSphereParamsRadius(spheresIds[i]));
m_pickableSpheres.push_back(pickable);
}
// Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
dock.fragmentEdit->setPlainText(QString(m_shader->getFragmentShaderSrc()));
// Update clipping parameters in interface
Utils::ClippingShader::clippingMode clipMode = m_shader->getClipMode();
if (clipMode == Utils::ClippingShader::CLIPPING_MODE_AND)
dock.radioButton_ClippingModeAnd->setChecked(true);
else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR)
dock.radioButton_ClippingModeOr->setChecked(true);
updateGLMatrices();
}
void Clipping::button_compile()
{
QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText();
......@@ -316,6 +493,14 @@ void Clipping::initGUI()
else if (colorAttMode == Utils::ClippingShader::COLOR_ATTENUATION_MODE_QUADRATIC)
dock.radioButton_ColorAttenuationModeQuadratic->setChecked(true);
setCallBack(dock.PushButton_ApplyClippingPreset, SIGNAL(clicked()), SLOT(slot_pushButton_applyClippingPreset()));
dock.comboBox_ClippingPresets->addItem("Dual Planes");
dock.comboBox_ClippingPresets->addItem("Cube");
dock.comboBox_ClippingPresets->addItem("Tube");
dock.comboBox_ClippingPresets->addItem("Molecule");
}
void Clipping::cb_Open()
......@@ -374,6 +559,8 @@ void Clipping::importMesh(std::string& filename)
setParamObject(gWidthObj, gPosObj.data()) ;
updateGLMatrices();
m_shader->setClipColorAttenuationFactorRelative(m_bb.maxSize(), 5.0);
}
/*******************************************************************************
......
......@@ -28,6 +28,7 @@
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/qtInputs.h"
#include "ui_clipping.h"
// inclure qtui.h juste après le ui_xxx.h
......@@ -51,6 +52,8 @@
#include "Utils/frameManipulator.h"
#include "Utils/clippingPresets.h"
#include "Utils/cgognStream.h"
#include "Utils/drawer.h"
......@@ -153,6 +156,8 @@ public slots:
void slot_pushButton_deleteSelectedObject();
void slot_pushButton_applyClippingPreset();
void button_compile();
};
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _CGoGN_CLIPPINGPRESETS_H_
#define _CGoGN_CLIPPINGPRESETS_H_
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
#include <vector>
#include <cmath>
namespace CGoGN
{
namespace Utils
{
class ClippingPreset
{
/***********************************************
*
* Constructors
*
***********************************************/
public :
/// public static constructor
static ClippingPreset* CreateEmptyPreset();
/**
* public static constructor
* @param center center 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 facing true means having facing planes
*/
static ClippingPreset* CreateDualPlanesPreset(Geom::Vec3f center, float size, int axis, bool facing);
/**
* public static constructor
* @param center center between planes
* @param size distance between planes
* @param facing true means having facing planes
*/
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 constructor (used by public static constructors)
ClippingPreset();
/***********************************************
*
* Preset settings
*
***********************************************/
public :
/**
* adds a clip plane to the preset
* @param normal clip plane normal
* @param origin clip plane origin
*/
void addClipPlane(Geom::Vec3f normal, Geom::Vec3f origin);
/**
* adds a clip sphere to the preset
* @param center clip sphere center
* @param radius clip sphere radius
*/
void addClipSphere(Geom::Vec3f center, float radius);
/**
* sets the clipping mode
* @param clipMode clipping mode
*/
void setClippingMode(ClippingShader::clippingMode clipMode);
private :
/// clip planes structure
struct clipPlane
{
Geom::Vec3f normal, origin;
};
/// clip planes array
std::vector<clipPlane> m_clipPlanes;
/// clip spheres structure
struct clipSphere
{
Geom::Vec3f center;
float radius;
};
/// clip spheres array
std::vector<clipSphere> m_clipSpheres;
/// clipping mode
ClippingShader::clippingMode m_clipMode;
/***********************************************
*
* Preset application
*
***********************************************/
public :
/**
* applies the preset on a clipping shader
* @param clipShader pointer to the clipping shader object
* @param planesIds returns the new added planes ids
* @param spheresIds returns the new added spheres ids
* @warning planesIds and spheresIds must not be NULL, otherwise the function does nothing
*/
void apply(ClippingShader* clipShader, std::vector<unsigned int> *planesIds, std::vector<unsigned int> *spheresIds);
};
} // namespace Utils
} // namespace CGoGN
#endif
......@@ -32,7 +32,6 @@
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
namespace CGoGN
{
......@@ -69,7 +68,7 @@ public:
* @return clip plane id (positive value on success, else -1)
* @warning insertClippingCode must be called first
*/
int addClipPlane();
unsigned int addClipPlane();
/*
* deletes a clip plane
......@@ -77,6 +76,9 @@ public:
*/
void deleteClipPlane(unsigned int id);
/// deletes all clip planes
void deleteAllClipPlanes();
/// gets the clip planes count
int getClipPlanesCount();
......@@ -164,7 +166,7 @@ public:
* @return clip sphere id (positive value on success, else -1)
* @warning insertClippingCode must be called first
*/
int addClipSphere();
unsigned int addClipSphere();
/*
* deletes a clip sphere
......@@ -172,6 +174,9 @@ public:
*/
void deleteClipSphere(unsigned int id);
/// deletes all clip spheres
void deleteAllClipSpheres();
/// gets the clip spheres count
int getClipSpheresCount();
......@@ -272,7 +277,14 @@ public:
* sets the color attenuation factor
* @param colorAttenuationFactor color attenuation factor
*/
void setClipColorAttenuationFactor(float colorAttenuationFactor);
void setClipColorAttenuationFactorAbsolute(float colorAttenuationFactor);
/**
* sets the color attenuation factor according to an object size
* @param size size with which the color attenuation will be normalized
* @param factor attenuation factor
*/
void setClipColorAttenuationFactorRelative(float size, float factor);
/// gets the color attenuation factor
float getClipColorAttenuationFactor();
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Utils/clippingPresets.h"
namespace CGoGN
{
namespace Utils
{
/***********************************************
*
* Constructors
*
***********************************************/
ClippingPreset* ClippingPreset::CreateEmptyPreset()
{
ClippingPreset *preset = new ClippingPreset;
return preset;
}
ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float size, int axis, bool facing)
{
ClippingPreset *preset = new ClippingPreset;
// Correct axis if necessary
if ((axis < 0) || (axis > 2))
axis = 0;
// Axis on which planes will be aligned
Geom::Vec3f positDir (0.0f, 0.0f, 0.0f);
positDir[axis] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[axis] = -1.0f;
// Facing of planes
float side = 1.0f;
if (facing)
side = -1.0f;
// Add planes to preset
preset->addClipPlane(positDir, center + positDir*(size / 2.0f)*(side));
preset->addClipPlane(negDir, center + negDir*(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::CreateCubePreset(Geom::Vec3f center, float size, bool facing)
{
ClippingPreset *preset = new ClippingPreset;
// Directions
Geom::Vec3f xAxisPos = Geom::Vec3f (1.0f, 0.0f, 0.0f);
Geom::Vec3f xAxisNeg = Geom::Vec3f (-1.0f, 0.0f, 0.0f);
Geom::Vec3f yAxisPos = Geom::Vec3f (0.0f, 1.0f, 0.0f);
Geom::Vec3f yAxisNeg = Geom::Vec3f (0.0f, -1.0f, 0.0f);
Geom::Vec3f zAxisPos = Geom::Vec3f (0.0f, 0.0f, 1.0f);
Geom::Vec3f zAxisNeg = Geom::Vec3f (0.0f, 0.0f, -1.0f);
// Facing of planes
float side = 1.0f;
if (facing)
side = -1.0f;
// Add planes to preset
preset->addClipPlane(xAxisPos, center + xAxisPos*(size / 2.0f)*(side));
preset->addClipPlane(xAxisNeg, center + xAxisNeg*(size / 2.0f)*(side));
preset->addClipPlane(yAxisPos, center + yAxisPos*(size / 2.0f)*(side));
preset->addClipPlane(yAxisNeg, center + yAxisNeg*(size / 2.0f)*(side));
preset->addClipPlane(zAxisPos, center + zAxisPos*(size / 2.0f)*(side));
preset->addClipPlane(zAxisNeg, center + zAxisNeg*(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::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;