Skip to content

Commit a442b6c

Browse files
committed
moved clipping plane geometries to viewscene
1 parent e146681 commit a442b6c

File tree

4 files changed

+145
-70
lines changed

4 files changed

+145
-70
lines changed

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

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
#include "comp/SRRenderState.h"
6262
#include "comp/RenderList.h"
6363
#include "comp/StaticWorldLight.h"
64-
#include "comp/StaticClippingPlanes.h"
6564
#include "comp/LightingUniforms.h"
6665
#include "comp/ClippingPlaneUniforms.h"
6766

@@ -1297,6 +1296,7 @@ namespace SCIRun {
12971296
std::abs(glm::dot(n, a3)),
12981297
std::abs(glm::dot(n, a4))));
12991298
}
1299+
13001300
void SRInterface::updateClippingPlanes()
13011301
{
13021302
StaticClippingPlanes* clippingPlanes = mCore.getStaticComponent<StaticClippingPlanes>();
@@ -1334,72 +1334,23 @@ namespace SCIRun {
13341334
i.showFrame ? 1.0 : 0.0,
13351335
i.reverseNormal ? 1.0 : 0.0, 0.0);
13361336
clippingPlanes->clippingPlaneCtrls.push_back(control);
1337-
if (i.showFrame)
1338-
updateGeometryClippingPlane(index, n);
1337+
//if (i.showFrame)
1338+
// updateGeometryClippingPlane(index, n);
13391339
index++;
13401340
}
13411341
}
13421342
}
13431343

1344-
//
1345-
void SRInterface::updateGeometryClippingPlane(int index, glm::vec4 plane)
1344+
StaticClippingPlanes* SRInterface::getClippingPlanes()
13461345
{
1347-
Core::Geometry::Vector diag(mSceneBBox.diagonal());
1348-
Core::Geometry::Point c(mSceneBBox.center());
1349-
Core::Geometry::Vector n(plane.x, plane.y, plane.z);
1350-
n.normalize();
1351-
Core::Geometry::Point p(c + (n * diag.length() / 2.0) * plane.w);
1352-
if (clippingPlanes_[index].reverseNormal)
1353-
n = -n;
1354-
double w, h; w = h = diag.length() / 2.0;
1355-
Core::Geometry::Vector axis1, axis2;
1356-
Point intersect;
1357-
n.find_orthogonal(axis1, axis2);
1358-
if (mSceneBBox.intersect(c, axis1, intersect))
1359-
w = std::max(w, 2.1 * (intersect - c).length());
1360-
if (mSceneBBox.intersect(c, axis2, intersect))
1361-
h = std::max(h, 2.1 * (intersect - c).length());
1362-
if (clippingPlanes_[index].reverseNormal)
1363-
p = Core::Geometry::Point(n * plane.w);
1364-
else
1365-
p = Core::Geometry::Point(-n * plane.w);
1366-
Core::Geometry::Point p1 = p - axis1 * w / 2.0 - axis2 * h / 2.0;
1367-
Core::Geometry::Point p2 = p + axis1 * w / 2.0 - axis2 * h / 2.0;
1368-
Core::Geometry::Point p3 = p + axis1 * w / 2.0 + axis2 * h / 2.0;
1369-
Core::Geometry::Point p4 = p - axis1 * w / 2.0 + axis2 * h / 2.0;
1346+
StaticClippingPlanes* clippingPlanes = mCore.getStaticComponent<StaticClippingPlanes>();
1347+
return clippingPlanes;
1348+
}
13701349

1371-
std::stringstream ss;
1372-
std::string uniqueNodeID;
1373-
1374-
Graphics::GlyphGeom glyphs;
1375-
glyphs.addClippingPlane(p1, p2, p3, p4, 0.01 * std::min(w, h),
1376-
50, ColorRGB(), ColorRGB());
1377-
ss << "clipping_plane" << index;
1378-
uniqueNodeID = ss.str();
1379-
ColorScheme colorScheme(COLOR_UNIFORM);
1380-
RenderState renState;
1381-
renState.set(RenderState::IS_ON, true);
1382-
renState.set(RenderState::USE_TRANSPARENCY, false);
1383-
renState.defaultColor = ColorRGB(0.4, 0.4, 1);
1384-
renState.set(RenderState::USE_DEFAULT_COLOR, true);
1385-
renState.set(RenderState::USE_NORMALS, true);
1386-
renState.set(RenderState::IS_WIDGET, true);
1387-
GeometryHandle geom(new GeometryObjectSpire(uniqueNodeID));
1388-
glyphs.buildObject(geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 1.0,
1389-
colorScheme, renState, SpireIBO::TRIANGLES, mSceneBBox);
1390-
handleGeomObject(geom, 0);
1391-
1392-
/* Graphics::GlyphGeom glyphs2;
1393-
glyphs2.addPlane(p1, p2, p3, p4, ColorRGB());
1394-
ss.str("");
1395-
ss << "clipping_plane_trans" << index;
1396-
uniqueNodeID = ss.str();
1397-
renState.set(RenderState::USE_TRANSPARENCY, true);
1398-
renState.defaultColor = ColorRGB(1, 1, 1, 0.2);
1399-
GeometryHandle geom2(new GeometryObjectSpire(ss.str()));
1400-
glyphs2.buildObject(geom2, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 0.2,
1401-
colorScheme, renState, SpireIBO::TRIANGLES, mSceneBBox);
1402-
handleGeomObject(geom2, 0);*/
1350+
//get scenenox
1351+
Core::Geometry::BBox SRInterface::getSceneBox()
1352+
{
1353+
return mSceneBBox;
14031354
}
14041355

14051356
//------------------------------------------------------------------------------

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// CPM Modules
4343
#include <es-render/util/Shader.hpp>
4444
#include <es-render/comp/CommonUniforms.hpp>
45-
45+
#include "comp/StaticClippingPlanes.h"
4646
#include <Graphics/Datatypes/GeometryImpl.h>
4747
#include <Interface/Modules/Render/share.h>
4848

@@ -90,6 +90,11 @@ namespace SCIRun {
9090
MOUSE_NEWSCIRUN
9191
};
9292

93+
struct ClippingPlane {
94+
bool visible, showFrame, reverseNormal;
95+
double x, y, z, d;
96+
};
97+
9398
void inputMouseDown(const glm::ivec2& pos, MouseButton btn);
9499
void inputMouseMove(const glm::ivec2& pos, MouseButton btn);
95100
void inputMouseUp(const glm::ivec2& pos, MouseButton btn);
@@ -172,6 +177,12 @@ namespace SCIRun {
172177
const glm::mat4& getViewToWorld() const;
173178
const glm::mat4& getViewToProjection() const;
174179

180+
//clipping planes
181+
StaticClippingPlanes* getClippingPlanes();
182+
183+
//get scenenox
184+
Core::Geometry::BBox getSceneBox();
185+
175186
private:
176187

177188
class DepthIndex {
@@ -239,11 +250,6 @@ namespace SCIRun {
239250
int mPort;
240251
};
241252

242-
struct ClippingPlane {
243-
bool visible, showFrame, reverseNormal;
244-
double x, y, z, d;
245-
};
246-
247253
// Sets up ESCore.
248254
void setupCore();
249255

@@ -296,9 +302,6 @@ namespace SCIRun {
296302
// make sure clipping plane number matches
297303
void checkClippingPlanes(int n);
298304

299-
// update clipping plane geometries
300-
void updateGeometryClippingPlane(int index, glm::vec4 plane);
301-
302305
bool showOrientation_; ///< Whether the coordinate axes will render or not.
303306
bool autoRotate_; ///< Whether the scene will continue to rotate.
304307
bool selectWidget_; ///< Whether mouse click will select a widget.

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ DEALINGS IN THE SOFTWARE.
3737
#include <Modules/Render/ViewScene.h>
3838
#include <Interface/Modules/Render/Screenshot.h>
3939
#include <boost/thread.hpp>
40+
#include <Graphics/Glyphs/GlyphGeom.h>
41+
#include <Graphics/Datatypes/GeometryImpl.h>
4042

4143
using namespace SCIRun::Gui;
4244
using namespace SCIRun::Dataflow::Networks;
@@ -383,18 +385,33 @@ void ViewSceneDialog::newGeometryValue()
383385
}
384386
//add objects of its own
385387
//scale bar
388+
++port;
386389
if (scaleBar_.visible && scaleBarGeom_)
387390
{
388391
auto name = scaleBarGeom_->uniqueID();
389392
auto displayName = QString::fromStdString(name).split('_').at(1);
390-
objectNames.push_back(displayName.toStdString());
393+
objectNames.push_back(name/*displayName.toStdString()*/);
391394
auto realObj = boost::dynamic_pointer_cast<Graphics::Datatypes::GeometryObjectSpire>(scaleBarGeom_);
392395
if (realObj)
393396
{
394397
spire->handleGeomObject(realObj, port);
395398
validObjects.push_back(name);
396399
}
397400
}
401+
++port;
402+
//clippingplanes
403+
for (auto i : clippingPlaneGeoms_)
404+
{
405+
auto name = i->uniqueID();
406+
auto displayName = QString::fromStdString(name).split('_').at(1);
407+
objectNames.push_back(name/*displayName.toStdString()*/);
408+
auto realObj = boost::dynamic_pointer_cast<Graphics::Datatypes::GeometryObjectSpire>(i);
409+
if (realObj)
410+
{
411+
spire->handleGeomObject(realObj, port);
412+
validObjects.push_back(name);
413+
}
414+
}
398415
spire->gcInvalidObjects(validObjects);
399416

400417
sort(objectNames.begin(), objectNames.end());
@@ -817,6 +834,7 @@ void ViewSceneDialog::setClippingPlaneVisible(bool value)
817834
auto spire = mSpire.lock();
818835
if (spire)
819836
spire->setClippingPlaneVisible(clippingPlanes_[clippingPlaneIndex_].visible);
837+
updatClippingPlaneDisplay();
820838
}
821839

822840
void ViewSceneDialog::setClippingPlaneFrameOn(bool value)
@@ -826,6 +844,7 @@ void ViewSceneDialog::setClippingPlaneFrameOn(bool value)
826844
auto spire = mSpire.lock();
827845
if (spire)
828846
spire->setClippingPlaneFrameOn(clippingPlanes_[clippingPlaneIndex_].showFrame);
847+
updatClippingPlaneDisplay();
829848
}
830849

831850
void ViewSceneDialog::reverseClippingPlaneNormal(bool value)
@@ -834,6 +853,7 @@ void ViewSceneDialog::reverseClippingPlaneNormal(bool value)
834853
auto spire = mSpire.lock();
835854
if (spire)
836855
spire->reverseClippingPlaneNormal(clippingPlanes_[clippingPlaneIndex_].reverseNormal);
856+
updatClippingPlaneDisplay();
837857
}
838858

839859
void ViewSceneDialog::setClippingPlaneX(int index)
@@ -879,6 +899,10 @@ void ViewSceneDialog::updatClippingPlaneDisplay()
879899
clippingPlanes_[clippingPlaneIndex_].y,
880900
clippingPlanes_[clippingPlaneIndex_].z,
881901
clippingPlanes_[clippingPlaneIndex_].d);
902+
903+
//geometry
904+
buildGeomClippingPlanes();
905+
newGeometryValue();
882906
}
883907

884908
//------------------------------------------------------------------------------
@@ -1167,6 +1191,98 @@ void ViewSceneDialog::updateScaleBarLength()
11671191
}
11681192
}
11691193

1194+
void ViewSceneDialog::buildGeomClippingPlanes()
1195+
{
1196+
auto spire = mSpire.lock();
1197+
if (!spire)
1198+
return;
1199+
StaticClippingPlanes* clippingPlanes = spire->getClippingPlanes();
1200+
1201+
clippingPlaneGeoms_.clear();
1202+
int index = 0;
1203+
for (auto i : clippingPlanes->clippingPlanes)
1204+
{
1205+
if (clippingPlanes_[index].showFrame)
1206+
buildGeometryClippingPlane(index, i, spire->getSceneBox());
1207+
index++;
1208+
}
1209+
}
1210+
1211+
//
1212+
void ViewSceneDialog::buildGeometryClippingPlane(
1213+
int index, glm::vec4 plane, SCIRun::Core::Geometry::BBox bbox)
1214+
{
1215+
Core::Geometry::Vector diag(bbox.diagonal());
1216+
Core::Geometry::Point c(bbox.center());
1217+
Core::Geometry::Vector n(plane.x, plane.y, plane.z);
1218+
n.normalize();
1219+
Core::Geometry::Point p(c + (n * diag.length() / 2.0) * plane.w);
1220+
if (clippingPlanes_[index].reverseNormal)
1221+
n = -n;
1222+
double w, h; w = h = diag.length() / 2.0;
1223+
Core::Geometry::Vector axis1, axis2;
1224+
Point intersect;
1225+
n.find_orthogonal(axis1, axis2);
1226+
if (bbox.intersect(c, axis1, intersect))
1227+
w = std::max(w, 2.1 * (intersect - c).length());
1228+
if (bbox.intersect(c, axis2, intersect))
1229+
h = std::max(h, 2.1 * (intersect - c).length());
1230+
if (clippingPlanes_[index].reverseNormal)
1231+
p = Core::Geometry::Point(n * plane.w);
1232+
else
1233+
p = Core::Geometry::Point(-n * plane.w);
1234+
Core::Geometry::Point p1 = p - axis1 * w / 2.0 - axis2 * h / 2.0;
1235+
Core::Geometry::Point p2 = p + axis1 * w / 2.0 - axis2 * h / 2.0;
1236+
Core::Geometry::Point p3 = p + axis1 * w / 2.0 + axis2 * h / 2.0;
1237+
Core::Geometry::Point p4 = p - axis1 * w / 2.0 + axis2 * h / 2.0;
1238+
1239+
std::stringstream ss;
1240+
std::string uniqueNodeID;
1241+
1242+
Graphics::GlyphGeom glyphs;
1243+
glyphs.addClippingPlane(p1, p2, p3, p4, 0.01 * std::min(w, h),
1244+
50, ColorRGB(), ColorRGB());
1245+
ss << "clipping_plane" << index <<
1246+
p1.x() << p1.y() << p1.z() <<
1247+
p2.x() << p2.y() << p2.z() <<
1248+
p3.x() << p3.y() << p3.z() <<
1249+
p4.x() << p4.y() << p4.z();
1250+
uniqueNodeID = ss.str();
1251+
Graphics::Datatypes::ColorScheme colorScheme(Graphics::Datatypes::ColorScheme::COLOR_UNIFORM);
1252+
RenderState renState;
1253+
renState.set(RenderState::IS_ON, true);
1254+
renState.set(RenderState::USE_TRANSPARENCY, false);
1255+
renState.defaultColor = ColorRGB(0.4, 0.4, 1);
1256+
renState.set(RenderState::USE_DEFAULT_COLOR, true);
1257+
renState.set(RenderState::USE_NORMALS, true);
1258+
renState.set(RenderState::IS_WIDGET, true);
1259+
SCIRun::Graphics::Datatypes::GeometryHandle geom(
1260+
new SCIRun::Graphics::Datatypes::GeometryObjectSpire(uniqueNodeID));
1261+
glyphs.buildObject(geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 1.0,
1262+
colorScheme, renState, SCIRun::Graphics::Datatypes::SpireIBO::TRIANGLES, bbox);
1263+
//handleGeomObject(geom, 0);
1264+
1265+
Graphics::GlyphGeom glyphs2;
1266+
glyphs2.addPlane(p1, p2, p3, p4, ColorRGB());
1267+
ss.str("");
1268+
ss << "clipping_plane_trans" << index <<
1269+
p1.x() << p1.y() << p1.z() <<
1270+
p2.x() << p2.y() << p2.z() <<
1271+
p3.x() << p3.y() << p3.z() <<
1272+
p4.x() << p4.y() << p4.z();
1273+
uniqueNodeID = ss.str();
1274+
renState.set(RenderState::USE_TRANSPARENCY, true);
1275+
renState.defaultColor = ColorRGB(1, 1, 1, 0.2);
1276+
SCIRun::Graphics::Datatypes::GeometryHandle geom2(
1277+
new SCIRun::Graphics::Datatypes::GeometryObjectSpire(ss.str()));
1278+
glyphs2.buildObject(geom2, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 0.2,
1279+
colorScheme, renState, SCIRun::Graphics::Datatypes::SpireIBO::TRIANGLES, bbox);
1280+
//handleGeomObject(geom2, 0);
1281+
1282+
clippingPlaneGeoms_.push_back(geom);
1283+
clippingPlaneGeoms_.push_back(geom2);
1284+
}
1285+
11701286
//------------------------------------------------------------------------------
11711287
//-------------------Render Settings--------------------------------------------
11721288
void ViewSceneDialog::lightingChecked(bool value)

src/Interface/Modules/Render/ViewScene.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ namespace SCIRun {
197197
Graphics::Datatypes::GeometryHandle buildGeometryScaleBar();
198198
void updateScaleBarLength();
199199

200+
// update clipping plane geometries
201+
void buildGeomClippingPlanes();
202+
void buildGeometryClippingPlane(int index, glm::vec4 plane, Core::Geometry::BBox bbox);
203+
200204
GLWidget* mGLWidget; ///< GL widget containing context.
201205
std::weak_ptr<Render::SRInterface> mSpire; ///< Instance of Spire.
202206
QToolBar* mToolBar; ///< Tool bar.
@@ -226,6 +230,7 @@ namespace SCIRun {
226230
//geometries
227231
Modules::Visualization::TextBuilder textBuilder_;
228232
Graphics::Datatypes::GeometryHandle scaleBarGeom_;
233+
std::vector<Graphics::Datatypes::GeometryHandle> clippingPlaneGeoms_;
229234

230235
friend class ViewSceneControlsDock;
231236
};

0 commit comments

Comments
 (0)