Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
CGoGN
CGoGN
Commits
6d942ba2
Commit
6d942ba2
authored
Aug 04, 2011
by
Maire Nicolas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Création d'une nouvelle classe clippingPreset pour application de presets de clipping.
parent
c32aac62
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
402 additions
and
4 deletions
+402
-4
include/Utils/clippingPresets.h
include/Utils/clippingPresets.h
+153
-0
include/Utils/clippingShader.h
include/Utils/clippingShader.h
+8
-2
src/Utils/clippingPresets.cpp
src/Utils/clippingPresets.cpp
+175
-0
src/Utils/clippingShader.cpp
src/Utils/clippingShader.cpp
+66
-2
No files found.
include/Utils/clippingPresets.h
0 → 100644
View file @
6d942ba2
/*******************************************************************************
* 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>
namespace
CGoGN
{
namespace
Utils
{
class
ClippingPreset
{
/***********************************************
*
* Constructors
*
***********************************************/
public
:
/// public static constructor
static
ClippingPreset
*
CreateEmptyPreset
();
/**
* public static constructor
* @param center center between planes
* @param distance 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
distance
,
int
axis
,
bool
facing
);
/**
* public static constructor
* @param center center between planes
* @param distance distance between planes
* @param facing true means having facing planes
*/
static
ClippingPreset
*
CreateCubePreset
(
Geom
::
Vec3f
center
,
float
distance
,
bool
facing
);
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
include/Utils/clippingShader.h
View file @
6d942ba2
...
...
@@ -69,7 +69,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 +77,9 @@ public:
*/
void
deleteClipPlane
(
unsigned
int
id
);
/// deletes all clip planes
void
deleteAllClipPlanes
();
/// gets the clip planes count
int
getClipPlanesCount
();
...
...
@@ -164,7 +167,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 +175,9 @@ public:
*/
void
deleteClipSphere
(
unsigned
int
id
);
/// deletes all clip spheres
void
deleteAllClipSpheres
();
/// gets the clip spheres count
int
getClipSpheresCount
();
...
...
src/Utils/clippingPresets.cpp
0 → 100644
View file @
6d942ba2
/*******************************************************************************
* 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
distance
,
int
axis
,
bool
facing
)
{
ClippingPreset
*
preset
=
new
ClippingPreset
;
// Axis on which planes will be aligned
if
((
axis
<
0
)
||
(
axis
>
2
))
axis
=
0
;
Geom
::
Vec3f
positDir
(
0.0
,
0.0
,
0.0
);
positDir
[
axis
]
=
1.0
;
Geom
::
Vec3f
negDir
(
0.0
,
0.0
,
0.0
);
negDir
[
axis
]
=
-
1.0
;
// Add planes to preset
preset
->
addClipPlane
(
positDir
,
center
+
positDir
*
(
distance
/
2.0
));
preset
->
addClipPlane
(
negDir
,
center
+
negDir
*
(
distance
/
2.0
));
// Set clipping mode
preset
->
setClippingMode
(
ClippingShader
::
CLIPPING_MODE_AND
);
return
preset
;
}
ClippingPreset
*
ClippingPreset
::
CreateCubePreset
(
Geom
::
Vec3f
center
,
float
distance
,
bool
facing
)
{
ClippingPreset
*
preset
=
new
ClippingPreset
;
// Directions
Geom
::
Vec3f
xAxisPos
=
Geom
::
Vec3f
(
1.0
,
0.0
,
0.0
);
Geom
::
Vec3f
xAxisNeg
=
Geom
::
Vec3f
(
-
1.0
,
0.0
,
0.0
);
Geom
::
Vec3f
yAxisPos
=
Geom
::
Vec3f
(
0.0
,
1.0
,
0.0
);
Geom
::
Vec3f
yAxisNeg
=
Geom
::
Vec3f
(
0.0
,
-
1.0
,
0.0
);
Geom
::
Vec3f
zAxisPos
=
Geom
::
Vec3f
(
0.0
,
0.0
,
1.0
);
Geom
::
Vec3f
zAxisNeg
=
Geom
::
Vec3f
(
0.0
,
0.0
,
-
1.0
);
// Add planes to preset
preset
->
addClipPlane
(
xAxisPos
,
center
+
xAxisPos
*
(
distance
/
2.0
));
preset
->
addClipPlane
(
xAxisNeg
,
center
+
xAxisNeg
*
(
distance
/
2.0
));
preset
->
addClipPlane
(
yAxisPos
,
center
+
yAxisPos
*
(
distance
/
2.0
));
preset
->
addClipPlane
(
yAxisNeg
,
center
+
yAxisNeg
*
(
distance
/
2.0
));
preset
->
addClipPlane
(
zAxisPos
,
center
+
zAxisPos
*
(
distance
/
2.0
));
preset
->
addClipPlane
(
zAxisNeg
,
center
+
zAxisNeg
*
(
distance
/
2.0
));
// Set clipping mode
preset
->
setClippingMode
(
ClippingShader
::
CLIPPING_MODE_AND
);
return
preset
;
}
ClippingPreset
::
ClippingPreset
()
:
m_clipMode
(
ClippingShader
::
CLIPPING_MODE_AND
)
{
}
/***********************************************
*
* Preset settings
*
***********************************************/
void
ClippingPreset
::
addClipPlane
(
Geom
::
Vec3f
normal
,
Geom
::
Vec3f
origin
)
{
clipPlane
newPlane
;
newPlane
.
normal
=
normal
;
newPlane
.
origin
=
origin
;
m_clipPlanes
.
push_back
(
newPlane
);
}
void
ClippingPreset
::
addClipSphere
(
Geom
::
Vec3f
center
,
float
radius
)
{
clipSphere
newSphere
;
newSphere
.
center
=
center
;
newSphere
.
radius
=
radius
;
m_clipSpheres
.
push_back
(
newSphere
);
}
void
ClippingPreset
::
setClippingMode
(
ClippingShader
::
clippingMode
clipMode
)
{
m_clipMode
=
clipMode
;
}
/***********************************************
*
* Preset application
*
***********************************************/
void
ClippingPreset
::
apply
(
ClippingShader
*
clipShader
,
std
::
vector
<
unsigned
int
>
*
planesIds
,
std
::
vector
<
unsigned
int
>
*
spheresIds
)
{
if
(
(
clipShader
==
NULL
)
||
(
planesIds
==
NULL
)
||
(
spheresIds
==
NULL
)
)
return
;
// Delete any remaining clip planes or spheres
clipShader
->
deleteAllClipPlanes
();
clipShader
->
deleteAllClipSpheres
();
// Initialize ids arrays (they should already be of zero size)
planesIds
->
resize
(
0
);
spheresIds
->
resize
(
0
);
// Add planes and spheres and get their ids
for
(
size_t
i
=
0
;
i
<
m_clipPlanes
.
size
();
i
++
)
{
unsigned
int
id
=
clipShader
->
addClipPlane
();
planesIds
->
push_back
(
id
);
clipShader
->
setClipPlaneParamsAll
(
id
,
m_clipPlanes
[
i
].
normal
,
m_clipPlanes
[
i
].
origin
);
}
for
(
size_t
i
=
0
;
i
<
m_clipSpheres
.
size
();
i
++
)
{
unsigned
int
id
=
clipShader
->
addClipSphere
();
spheresIds
->
push_back
(
id
);
clipShader
->
setClipSphereParamsAll
(
id
,
m_clipSpheres
[
i
].
center
,
m_clipSpheres
[
i
].
radius
);
}
// Set new clipping mode
clipShader
->
setClipMode
(
m_clipMode
);
}
}
// namespace Utils
}
// namespace CGoGN
src/Utils/clippingShader.cpp
View file @
6d942ba2
...
...
@@ -61,7 +61,7 @@ ClippingShader::ClippingShader():
***********************************************/
int
ClippingShader
::
addClipPlane
()
unsigned
int
ClippingShader
::
addClipPlane
()
{
// Check if the clipping code has been inserted into shader
if
(
errorRaiseClippingCodeNotInserted
(
!
m_hasClippingCodeBeenInserted
,
"ClippingShader::addClipPlane"
))
...
...
@@ -159,6 +159,38 @@ void ClippingShader::deleteClipPlane(unsigned int id)
recompile
();
}
void
ClippingShader
::
deleteAllClipPlanes
()
{
// Check if the clipping code has been inserted into shader
if
(
errorRaiseClippingCodeNotInserted
(
!
m_hasClippingCodeBeenInserted
,
"ClippingShader::deleteAllClipPlanes"
))
return
;
// Shader name string
std
::
string
shaderName
=
m_nameVS
+
"/"
+
m_nameFS
+
"/"
+
m_nameGS
;
// Use a shader mutator
ShaderMutator
SM
(
shaderName
,
getVertexShaderSrc
(),
getFragmentShaderSrc
());
// Modify the clip planes count constant in both shader
if
(
errorRaiseShaderMutatorFailure
(
(
!
SM
.
changeIntConstantValue
(
ShaderMutator
::
VERTEX_SHADER
,
"CLIP_PLANES_COUNT"
,
0
))
||
(
!
SM
.
changeIntConstantValue
(
ShaderMutator
::
FRAGMENT_SHADER
,
"CLIP_PLANES_COUNT"
,
0
)),
"ClippingShader::deleteAllClipPlanes"
))
return
;
// Reload both shaders
reloadVertexShaderFromMemory
(
SM
.
getModifiedVertexShaderSrc
().
c_str
());
reloadFragmentShaderFromMemory
(
SM
.
getModifiedFragmentShaderSrc
().
c_str
());
// Rearrange planes arrays
m_clipPlanes
.
resize
(
0
);
m_clipPlanesIds
.
resize
(
0
);
m_clipPlanesEquations
.
resize
(
0
);
// Recompile shaders (automatically calls updateClippingUniforms)
recompile
();
}
int
ClippingShader
::
getClipPlanesCount
()
{
return
(
int
)
m_clipPlanes
.
size
();
...
...
@@ -323,7 +355,7 @@ void ClippingShader::updateClipPlaneUniformsArray(unsigned int id)
***********************************************/
int
ClippingShader
::
addClipSphere
()
unsigned
int
ClippingShader
::
addClipSphere
()
{
// Check if the clipping code has been inserted into shader
if
(
errorRaiseClippingCodeNotInserted
(
!
m_hasClippingCodeBeenInserted
,
"ClippingShader::addClipSphere"
))
...
...
@@ -421,6 +453,38 @@ void ClippingShader::deleteClipSphere(unsigned int id)
recompile
();
}
void
ClippingShader
::
deleteAllClipSpheres
()
{
// Check if the clipping code has been inserted into shader
if
(
errorRaiseClippingCodeNotInserted
(
!
m_hasClippingCodeBeenInserted
,
"ClippingShader::deleteAllClipSpheres"
))
return
;
// Shader name string
std
::
string
shaderName
=
m_nameVS
+
"/"
+
m_nameFS
+
"/"
+
m_nameGS
;
// Use a shader mutator
ShaderMutator
SM
(
shaderName
,
getVertexShaderSrc
(),
getFragmentShaderSrc
());
// Modify the clip spheres count constant in both shader
if
(
errorRaiseShaderMutatorFailure
(
(
!
SM
.
changeIntConstantValue
(
ShaderMutator
::
VERTEX_SHADER
,
"CLIP_SPHERES_COUNT"
,
0
))
||
(
!
SM
.
changeIntConstantValue
(
ShaderMutator
::
FRAGMENT_SHADER
,
"CLIP_SPHERES_COUNT"
,
0
)),
"ClippingShader::deleteAllClipSpheres"
))
return
;
// Reload both shaders
reloadVertexShaderFromMemory
(
SM
.
getModifiedVertexShaderSrc
().
c_str
());
reloadFragmentShaderFromMemory
(
SM
.
getModifiedFragmentShaderSrc
().
c_str
());
// Rearrange spheres arrays
m_clipSpheres
.
resize
(
0
);
m_clipSpheresIds
.
resize
(
0
);
m_clipSpheresCentersAndRadiuses
.
resize
(
0
);
// Recompile shaders (automatically calls updateClippingUniforms)
recompile
();
}
int
ClippingShader
::
getClipSpheresCount
()
{
return
(
int
)
m_clipSpheres
.
size
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment