Skip to content

Commit a767fde

Browse files
committed
Merge pull request #1332 from basisunus/add_clip
fix clipping plane bounding box
2 parents 0ad5eb6 + f6e72ff commit a767fde

25 files changed

+1104
-334
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
sudo: required
12
language:
23
- cpp
34

src/Core/Datatypes/Geometry.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ GeometryObject::GeometryObject(const GeometryIDGenerator& idGenerator, const std
3636
{
3737
}
3838

39+
GeometryObject::GeometryObject(const std::string& tag) :
40+
objectName_(tag)
41+
{
42+
}
43+
3944
GeometryObject* GeometryObject::clone() const
4045
{
4146
return nullptr; //TODO

src/Core/Datatypes/Geometry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace Datatypes
4343
{
4444
public:
4545
GeometryObject(const GeometryIDGenerator& idGenerator, const std::string& tag);
46+
GeometryObject(const std::string& tag);
4647

4748
GeometryObject(const GeometryObject& other) = delete;
4849
GeometryObject& operator=(const GeometryObject& other) = delete;

src/Graphics/Datatypes/GeometryImpl.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,18 @@ GeometryObjectSpire::GeometryObjectSpire(const GeometryIDGenerator& idGenerator,
3535
GeometryObject(idGenerator, tag),
3636
mLowestValue(0.0),
3737
mHighestValue(0.0),
38-
isVisible(true)
38+
isVisible(true),
39+
isClippable(true)
3940
{
4041

42+
}
43+
44+
GeometryObjectSpire::GeometryObjectSpire(const std::string& tag) :
45+
GeometryObject(tag),
46+
mLowestValue(0.0),
47+
mHighestValue(0.0),
48+
isVisible(true),
49+
isClippable(false)
50+
{
51+
4152
}

src/Graphics/Datatypes/GeometryImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ namespace SCIRun {
258258
{
259259
public:
260260
GeometryObjectSpire(const Core::GeometryIDGenerator& idGenerator, const std::string& tag);
261+
GeometryObjectSpire(const std::string& tag);
261262

262263
std::list<SpireVBO> mVBOs; ///< Array of vertex buffer objects.
263264
std::list<SpireIBO> mIBOs; ///< Array of index buffer objects.
@@ -272,6 +273,7 @@ namespace SCIRun {
272273
double mHighestValue; ///< Highest value a field takes on.
273274

274275
bool isVisible;
276+
bool isClippable;
275277
};
276278

277279
typedef boost::shared_ptr<GeometryObjectSpire> GeometryHandle;

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ void GlyphGeom::buildObject(GeometryHandle geom, const std::string& uniqueNodeID
113113
ColorRGB dft = state.defaultColor;
114114
if (useTriangles)
115115
{
116-
shader = "Shaders/DirPhong";
116+
if (geom->isClippable)
117+
shader = "Shaders/DirPhong";
118+
else
119+
shader = "Shaders/DirPhongNoClipping";
117120
uniforms.push_back(SpireSubPass::Uniform("uAmbientColor",
118121
glm::vec4(0.1f, 0.1f, 0.1f, 1.0f)));
119122
uniforms.push_back(SpireSubPass::Uniform("uDiffuseColor",
@@ -237,6 +240,27 @@ void GlyphGeom::addCone(const Point p1, const Point& p2, double radius, double r
237240
generateCylinder(p1, p2, radius, 0.0, resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
238241
}
239242

243+
void GlyphGeom::addClippingPlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
244+
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4, double radius, double resolution,
245+
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2)
246+
{
247+
addSphere(p1, radius, resolution, color1);
248+
addSphere(p2, radius, resolution, color1);
249+
addSphere(p3, radius, resolution, color1);
250+
addSphere(p4, radius, resolution, color1);
251+
addCylinder(p1, p2, radius, resolution, color1, color2);
252+
addCylinder(p2, p3, radius, resolution, color1, color2);
253+
addCylinder(p3, p4, radius, resolution, color1, color2);
254+
addCylinder(p4, p1, radius, resolution, color1, color2);
255+
}
256+
257+
void GlyphGeom::addPlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
258+
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4,
259+
const Core::Datatypes::ColorRGB& color1)
260+
{
261+
generatePlane(p1, p2, p3, p4, color1, numVBOElements_, points_, normals_, indices_, colors_);
262+
}
263+
240264
void GlyphGeom::addLine(Point p1, const Point& p2, const ColorRGB& color1, const ColorRGB& color2)
241265
{
242266
generateLine(p1, p2, color1, color2, numVBOElements_, points_, indices_, colors_);
@@ -432,7 +456,36 @@ void GlyphGeom::generatePoint(const Point p, const ColorRGB& color,
432456
++numVBOElements;
433457
}
434458

435-
459+
void GlyphGeom::generatePlane(const Core::Geometry::Point p1, const Core::Geometry::Point p2,
460+
const Core::Geometry::Point p3, const Core::Geometry::Point p4, const Core::Datatypes::ColorRGB& color,
461+
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<Core::Geometry::Vector>& normals,
462+
std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors)
463+
{
464+
points.push_back(Vector(p1));
465+
points.push_back(Vector(p2));
466+
points.push_back(Vector(p3));
467+
points.push_back(Vector(p4));
468+
colors.push_back(color);
469+
colors.push_back(color);
470+
colors.push_back(color);
471+
colors.push_back(color);
472+
Vector n;
473+
n = Cross(p2 - p1, p4 - p1).normal();
474+
normals.push_back(n);
475+
n = Cross(p3 - p2, p1 - p2).normal();
476+
normals.push_back(n);
477+
n = Cross(p4 - p3, p2 - p3).normal();
478+
normals.push_back(n);
479+
n = Cross(p1 - p4, p3 - p4).normal();
480+
normals.push_back(n);
481+
indices.push_back(0 + numVBOElements);
482+
indices.push_back(1 + numVBOElements);
483+
indices.push_back(2 + numVBOElements);
484+
indices.push_back(2 + numVBOElements);
485+
indices.push_back(3 + numVBOElements);
486+
indices.push_back(0 + numVBOElements);
487+
numVBOElements += 4;
488+
}
436489

437490
// Addarrow from SCIRun 4
438491
void GlyphGeom::addArrow(const Point& center, const Vector& t,

src/Graphics/Glyphs/GlyphGeom.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ namespace SCIRun {
6262
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
6363
void addCone(const Core::Geometry::Point p1, const Core::Geometry::Point& p2, double radius, double resolution,
6464
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
65+
void addClippingPlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
66+
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4, double radius, double resolution,
67+
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
68+
void addPlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
69+
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4,
70+
const Core::Datatypes::ColorRGB& color1);
6571

6672
void addLine(const Core::Geometry::Point p1, const Core::Geometry::Point& p2,
6773
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
@@ -94,6 +100,9 @@ namespace SCIRun {
94100
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
95101
void generatePoint(const Core::Geometry::Point p, const Core::Datatypes::ColorRGB& color,
96102
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
103+
void generatePlane(const Core::Geometry::Point p1, const Core::Geometry::Point p2,
104+
const Core::Geometry::Point p3, const Core::Geometry::Point p4, const Core::Datatypes::ColorRGB& color,
105+
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<Core::Geometry::Vector>& normals, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
97106

98107
//From SCIRun4
99108
void generateBox(const Core::Geometry::Point& center, const Core::Geometry::Vector& t, double x_side, double y_side, double z_side, std::vector<QuadStrip>& quadstrips);

src/Interface/Modules/Render/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ TARGET_LINK_LIBRARIES(Interface_Modules_Render
9393
Interface_Modules_Base
9494
Core_Application_Preferences
9595
Core_Application
96-
Core_Datatypes
9796
${OPENGL_LIBRARIES}
9897
${QT_OPENGL_LIBRARY}
9998
${CPM_LIBRARIES}

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#include <Interface/Modules/Render/ES/SRCamera.h>
3636

3737
#include <Core/Application/Application.h>
38-
#include <Modules/Visualization/ShowColorMapModule.h>
38+
//#include <Modules/Visualization/ShowColorMapModule.h>
39+
#include <Graphics/Glyphs/GlyphGeom.h>
3940

4041
// CPM modules.
4142
#include <es-general/comp/StaticScreenDims.hpp>
@@ -60,7 +61,6 @@
6061
#include "comp/SRRenderState.h"
6162
#include "comp/RenderList.h"
6263
#include "comp/StaticWorldLight.h"
63-
#include "comp/StaticClippingPlanes.h"
6464
#include "comp/LightingUniforms.h"
6565
#include "comp/ClippingPlaneUniforms.h"
6666

@@ -75,8 +75,6 @@ namespace fs = CPM_ES_FS_NS;
7575
namespace SCIRun {
7676
namespace Render {
7777

78-
std::string SRInterface::mFSRoot;
79-
std::string SRInterface::mFSSeparator;
8078
//------------------------------------------------------------------------------
8179
SRInterface::SRInterface(std::shared_ptr<Gui::GLContext> context,
8280
int frameInitLimit) :
@@ -145,10 +143,6 @@ namespace SCIRun {
145143
mCore.addStaticComponent(iface);
146144
}
147145

148-
std::string filesystemRoot = Core::Application::Instance().executablePath().string();
149-
std::string sep;
150-
sep += boost::filesystem::path::preferred_separator;
151-
Modules::Visualization::ShowColorMapModule::setFSStrings(filesystemRoot, sep);
152146
}
153147

154148
//------------------------------------------------------------------------------
@@ -558,16 +552,6 @@ namespace SCIRun {
558552
return mWidgetTransform;
559553
}
560554

561-
std::string &SRInterface::getFSRoot()
562-
{
563-
return mFSRoot;
564-
}
565-
566-
std::string &SRInterface::getFSSeparator()
567-
{
568-
return mFSSeparator;
569-
}
570-
571555
//------------------------------------------------------------------------------
572556
//--------------Clipping Plane Tools--------------------------------------------
573557
void SRInterface::checkClippingPlanes(int n)
@@ -602,6 +586,7 @@ namespace SCIRun {
602586
{
603587
checkClippingPlanes(clippingPlaneIndex_);
604588
clippingPlanes_[clippingPlaneIndex_].showFrame = value;
589+
updateClippingPlanes();
605590
}
606591

607592
void SRInterface::reverseClippingPlaneNormal(bool value)
@@ -639,6 +624,36 @@ namespace SCIRun {
639624
updateClippingPlanes();
640625
}
641626

627+
const glm::mat4& SRInterface::getWorldToProjection() const
628+
{ return mCamera->getWorldToProjection(); }
629+
630+
const glm::mat4& SRInterface::getWorldToView() const
631+
{ return mCamera->getWorldToView(); }
632+
633+
const glm::mat4& SRInterface::getViewToWorld() const
634+
{ return mCamera->getViewToWorld(); }
635+
636+
const glm::mat4& SRInterface::getViewToProjection() const
637+
{ return mCamera->getViewToProjection(); }
638+
639+
//------------------------------------------------------------------------------
640+
/*void SRInterface::setScaleBar(const ScaleBar &scaleBarData)
641+
{
642+
scaleBar_.visible = scaleBarData.visible;
643+
scaleBar_.fontSize = scaleBarData.fontSize;
644+
scaleBar_.length = scaleBarData.length;
645+
scaleBar_.height = scaleBarData.height;
646+
scaleBar_.multiplier = scaleBarData.multiplier;
647+
scaleBar_.numTicks = scaleBarData.numTicks;
648+
scaleBar_.lineWidth = scaleBarData.lineWidth;
649+
scaleBar_.unit = scaleBarData.unit;
650+
if (scaleBar_.visible)
651+
{
652+
updateScaleBarLength();
653+
updateGeometryScaleBar();
654+
}
655+
}*/
656+
642657
//------------------------------------------------------------------------------
643658
void SRInterface::inputMouseUp(const glm::ivec2& /*pos*/, MouseButton /*btn*/)
644659
{
@@ -1267,22 +1282,77 @@ namespace SCIRun {
12671282
}
12681283

12691284
//
1285+
double SRInterface::getMaxProjLength(const glm::vec3 &n)
1286+
{
1287+
glm::vec3 a1(-1.0, 1.0, -1.0);
1288+
glm::vec3 a2(-1.0, 1.0, 1.0);
1289+
glm::vec3 a3(1.0, 1.0, -1.0);
1290+
glm::vec3 a4(1.0, 1.0, 1.0);
1291+
return std::max(
1292+
std::max(
1293+
std::abs(glm::dot(n, a1)),
1294+
std::abs(glm::dot(n, a2))),
1295+
std::max(
1296+
std::abs(glm::dot(n, a3)),
1297+
std::abs(glm::dot(n, a4))));
1298+
}
1299+
12701300
void SRInterface::updateClippingPlanes()
12711301
{
12721302
StaticClippingPlanes* clippingPlanes = mCore.getStaticComponent<StaticClippingPlanes>();
12731303
if (clippingPlanes)
12741304
{
12751305
clippingPlanes->clippingPlanes.clear();
12761306
clippingPlanes->clippingPlaneCtrls.clear();
1307+
//boundbox transformation
1308+
glm::mat4 trans_bb;
1309+
glm::vec3 scale_bb(mSceneBBox.x_length() / 2.0, mSceneBBox.y_length() / 2.0, mSceneBBox.z_length() / 2.0);
1310+
glm::vec3 center_bb(mSceneBBox.center().x(), mSceneBBox.center().y(), mSceneBBox.center().z());
1311+
trans_bb = glm::scale(trans_bb, scale_bb);
1312+
trans_bb = glm::translate(trans_bb, center_bb);
1313+
int index = 0;
12771314
for (auto i : clippingPlanes_)
12781315
{
1279-
clippingPlanes->clippingPlanes.push_back(glm::vec4(i.x, i.y, i.z, i.d));
1280-
clippingPlanes->clippingPlaneCtrls.push_back(
1281-
glm::vec4(i.visible?1.0:0.0, i.showFrame?1.0:0.0, i.reverseNormal?1.0:0.0, 0.0));
1316+
glm::vec3 n3(i.x, i.y, i.z);
1317+
double d = i.d;
1318+
glm::vec4 n(0.0);
1319+
if (glm::length(n3) > 0.0)
1320+
{
1321+
n3 = glm::normalize(n3);
1322+
n = glm::vec4(n3, 0.0);
1323+
d *= getMaxProjLength(n3);
1324+
}
1325+
glm::vec4 o = glm::vec4(n.x, n.y, n.z, 1.0) * d;
1326+
o.w = 1;
1327+
o = trans_bb * o;
1328+
n = glm::inverseTranspose(trans_bb) * n;
1329+
o.w = 0;
1330+
n.w = 0;
1331+
n.w = glm::dot(o, n);
1332+
clippingPlanes->clippingPlanes.push_back(n);
1333+
glm::vec4 control(i.visible ? 1.0 : 0.0,
1334+
i.showFrame ? 1.0 : 0.0,
1335+
i.reverseNormal ? 1.0 : 0.0, 0.0);
1336+
clippingPlanes->clippingPlaneCtrls.push_back(control);
1337+
//if (i.showFrame)
1338+
// updateGeometryClippingPlane(index, n);
1339+
index++;
12821340
}
12831341
}
12841342
}
12851343

1344+
StaticClippingPlanes* SRInterface::getClippingPlanes()
1345+
{
1346+
StaticClippingPlanes* clippingPlanes = mCore.getStaticComponent<StaticClippingPlanes>();
1347+
return clippingPlanes;
1348+
}
1349+
1350+
//get scenenox
1351+
Core::Geometry::BBox SRInterface::getSceneBox()
1352+
{
1353+
return mSceneBBox;
1354+
}
1355+
12861356
//------------------------------------------------------------------------------
12871357
void SRInterface::renderCoordinateAxes()
12881358
{

0 commit comments

Comments
 (0)