Skip to content

Commit 1855cab

Browse files
Rene BrunRene Brun
Rene Brun
authored and
Rene Brun
committed
From Timur
New code to draw shapes outline git-svn-id: http://root.cern.ch/svn/root/trunk@11931 27541ba8-7e3a-0410-8455-c3a389f83636
1 parent 72a505c commit 1855cab

8 files changed

+156
-12
lines changed

Diff for: gl/inc/TGLDrawable.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLDrawable.h,v 1.4 2005/05/28 12:21:00 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLDrawable.h,v 1.5 2005/06/01 12:38:25 brun Exp $
22
// Author: Richard Maunder 25/05/2005
33

44
/*************************************************************************
@@ -53,6 +53,16 @@ class TGLDrawable
5353

5454
virtual void Draw(UInt_t LOD) const;
5555

56+
virtual void DrawWireFrame(UInt_t lod) const
57+
{
58+
DirectDraw(lod);
59+
}
60+
virtual void DrawOutline(UInt_t lod) const
61+
{
62+
DirectDraw(lod);
63+
}
64+
65+
5666
// Caching
5767
bool SetDLCache(bool DLCache);
5868
virtual bool UseDLCache(UInt_t LOD) const;

Diff for: gl/inc/TGLPhysicalShape.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLPhysicalShape.h,v 1.3 2005/05/26 12:29:50 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLPhysicalShape.h,v 1.4 2005/06/01 12:38:25 brun Exp $
22
// Author: Richard Maunder 25/05/2005
33
// Parts taken from original TGLSceneObject Timur Pocheptsov
44

@@ -57,6 +57,8 @@ class TGLPhysicalShape : public TGLDrawable
5757
const TGLLogicalShape & GetLogical() const { return fLogicalShape; }
5858

5959
virtual void Draw(UInt_t LOD) const;
60+
virtual void DrawWireFrame(UInt_t lod) const;
61+
virtual void DrawOutline(UInt_t lod) const;
6062
void InvokeContextMenu(TContextMenu & menu, UInt_t x, UInt_t y) const;
6163

6264
// Selection

Diff for: gl/inc/TGLScene.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLScene.h,v 1.4 2005/05/26 12:29:50 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLScene.h,v 1.5 2005/06/01 12:38:25 brun Exp $
22
// Author: Richard Maunder 25/05/2005
33
// Parts taken from original TGLRender by Timur Pocheptsov
44

@@ -72,6 +72,15 @@ class TGLScene
7272
TGLScene(const TGLScene &);
7373
TGLScene & operator=(const TGLScene &);
7474

75+
public:
76+
enum EDrawMode{kFill, kOutline, kWireFrame};
77+
78+
void SetDrawMode(EDrawMode mode){fDrawMode = mode;}
79+
80+
private:
81+
EDrawMode fDrawMode;
82+
83+
7584
public:
7685
TGLScene();
7786
virtual ~TGLScene(); // ClassDef introduces virtual fns

Diff for: gl/inc/TGLSceneObject.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLSceneObject.h,v 1.23 2005/04/01 13:53:18 brun Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLSceneObject.h,v 1.25 2005/05/25 14:25:16 brun Exp $
22
// Author: Timur Pocheptsov 03/08/2004
33

44
/*************************************************************************
@@ -72,6 +72,8 @@ class TGLFaceSet : public TGLSceneObject {
7272
TGLFaceSet(const TBuffer3D &buff, TObject *realObj);
7373
void SetFromMesh(const RootCsg::BaseMesh *m);
7474
//void Stretch(Double_t xs, Double_t ys, Double_t zs);
75+
void DrawWireFrame(UInt_t) const;
76+
void DrawOutline(UInt_t) const;
7577

7678
private:
7779
void GLDrawPolys()const;

Diff for: gl/src/TGLPhysicalShape.cxx

+62-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLPhysicalShape.cxx,v 1.3 2005/05/26 12:29:50 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLPhysicalShape.cxx,v 1.4 2005/06/01 12:38:25 brun Exp $
22
// Author: Richard Maunder 25/05/2005
33

44
/*************************************************************************
@@ -140,6 +140,67 @@ void TGLPhysicalShape::DirectDraw(UInt_t LOD) const
140140
glPopMatrix();
141141
}
142142

143+
//______________________________________________________________________________
144+
void TGLPhysicalShape::DrawWireFrame(UInt_t lod) const
145+
{
146+
glPushMatrix();
147+
glLoadName(ID());
148+
glMultMatrixd(fTransform.CArr());
149+
150+
if (IsTransparent()) {
151+
glEnable(GL_BLEND);
152+
glDepthMask(GL_FALSE);
153+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
154+
}
155+
156+
glColor4fv(fColor);
157+
158+
if (fInvertedWind) glFrontFace(GL_CW);
159+
fLogicalShape.DrawWireFrame(lod);
160+
if (fInvertedWind) glFrontFace(GL_CCW);
161+
162+
if (IsTransparent()) {
163+
glDepthMask(GL_TRUE);
164+
glDisable(GL_BLEND);
165+
}
166+
167+
glPopMatrix();
168+
}
169+
170+
//______________________________________________________________________________
171+
void TGLPhysicalShape::DrawOutline(UInt_t LOD) const
172+
{
173+
// TODO: Can be moved to a one off switch when transparent draw sorting
174+
// back in
175+
glPushMatrix();
176+
glLoadName(ID());
177+
glMultMatrixd(fTransform.CArr());
178+
179+
if (IsTransparent()) {
180+
glEnable(GL_BLEND);
181+
glDepthMask(GL_FALSE);
182+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
183+
}
184+
185+
//TODO: Sorting - Min. state swap for attributes
186+
glMaterialfv(GL_FRONT, GL_DIFFUSE, fColor);
187+
glMaterialfv(GL_FRONT, GL_AMBIENT, fColor + 4);
188+
glMaterialfv(GL_FRONT, GL_SPECULAR, fColor + 8);
189+
glMaterialfv(GL_FRONT, GL_EMISSION, fColor + 12);
190+
glMaterialf(GL_FRONT, GL_SHININESS, fColor[16]);
191+
192+
if (fInvertedWind) glFrontFace(GL_CW);
193+
fLogicalShape.DrawOutline(LOD);
194+
if (fInvertedWind) glFrontFace(GL_CCW);
195+
196+
if (IsTransparent()) {
197+
glDepthMask(GL_TRUE);
198+
glDisable(GL_BLEND);
199+
}
200+
201+
glPopMatrix();
202+
}
203+
143204
//______________________________________________________________________________
144205
void TGLPhysicalShape::InvokeContextMenu(TContextMenu & menu, UInt_t x, UInt_t y) const
145206
{

Diff for: gl/src/TGLScene.cxx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLScene.cxx,v 1.4 2005/05/26 12:29:50 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLScene.cxx,v 1.5 2005/06/01 12:38:25 brun Exp $
22
// Author: Richard Maunder 25/05/2005
33
// Parts taken from original TGLRender by Timur Pocheptsov
44

@@ -268,7 +268,14 @@ void TGLScene::Draw(const TGLCamera & camera, UInt_t sceneLOD, Double_t timeout)
268268
++physicalShapeIt;
269269
continue;
270270
}
271-
physicalShape->Draw(shapeLOD);
271+
272+
//Draw, DrawWireFrame, DrawOutline
273+
if (fDrawMode == kFill)
274+
physicalShape->Draw(shapeLOD);
275+
else if (fDrawMode == kWireFrame)
276+
physicalShape->DrawWireFrame(shapeLOD);
277+
else
278+
physicalShape->DrawOutline(shapeLOD);
272279

273280
}
274281
++physicalShapeIt;

Diff for: gl/src/TGLSceneObject.cxx

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TGLSceneObject.cxx,v 1.38 2005/05/28 12:21:00 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TGLSceneObject.cxx,v 1.39 2005/06/01 12:38:25 brun Exp $
22
// Author: Timur Pocheptsov 03/08/2004
33

44
/*************************************************************************
@@ -247,6 +247,44 @@ void TGLFaceSet::DirectDraw(UInt_t /*LOD*/) const
247247
}
248248
}
249249

250+
//______________________________________________________________________________
251+
void TGLFaceSet::DrawWireFrame(UInt_t) const
252+
{
253+
const Double_t *pnts = &fVertices[0];
254+
const Int_t *pols = &fPolyDesc[0];
255+
256+
257+
for (UInt_t i = 0, j = 0; i < fNbPols; ++i) {
258+
Int_t npoints = pols[j++];
259+
260+
glBegin(GL_POLYGON);
261+
262+
for (Int_t k = 0; k < npoints; ++k, ++j)
263+
glVertex3dv(pnts + pols[j] * 3);
264+
265+
glEnd();
266+
}
267+
}
268+
269+
//______________________________________________________________________________
270+
void TGLFaceSet::DrawOutline(UInt_t lod) const
271+
{
272+
glEnable(GL_POLYGON_OFFSET_FILL);
273+
glPolygonOffset(1.f, 1.f);
274+
275+
DirectDraw(lod);
276+
277+
glDisable(GL_POLYGON_OFFSET_FILL);
278+
glDisable(GL_LIGHTING);
279+
glPolygonMode(GL_FRONT, GL_LINE);
280+
glColor3d(.1, .1, .1);
281+
282+
DirectDraw(lod);
283+
284+
glPolygonMode(GL_FRONT, GL_FILL);
285+
glEnable(GL_LIGHTING);
286+
}
287+
250288
//______________________________________________________________________________
251289
Int_t TGLFaceSet::CheckPoints(const Int_t *source, Int_t *dest) const
252290
{

Diff for: gl/src/TViewerOpenGL.cxx

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gl:$Name: $:$Id: TViewerOpenGL.cxx,v 1.59 2005/05/28 12:21:00 rdm Exp $
1+
// @(#)root/gl:$Name: $:$Id: TViewerOpenGL.cxx,v 1.60 2005/06/01 12:38:25 brun Exp $
22
// Author: Timur Pocheptsov 03/08/2004
33

44
/*************************************************************************
@@ -535,6 +535,8 @@ Bool_t TViewerOpenGL::HandleContainerKey(Event_t *event)
535535
{
536536
char tmp[10] = {0};
537537
UInt_t keysym = 0;
538+
Float_t black[] = {0.f, 0.f, 0.f, 1.f};
539+
Float_t white[] = {1.f, 1.f, 1.f, 1.f};
538540

539541
gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
540542

@@ -553,16 +555,29 @@ Bool_t TViewerOpenGL::HandleContainerKey(Event_t *event)
553555
break;
554556
case kKey_R:
555557
case kKey_r:
556-
gVirtualGL->PolygonGLMode(kFRONT, kFILL);
558+
gVirtualGL->EnableGL(kLIGHTING);
557559
gVirtualGL->EnableGL(kCULL_FACE);
558-
gVirtualGL->SetGLLineWidth(1.f);
560+
gVirtualGL->PolygonGLMode(kFRONT, kFILL);
561+
gVirtualGL->ClearGLColor(black[0], black[1], black[2], black[3]);
562+
fScene.SetDrawMode(TGLScene::kFill);
559563
invalidate = kTRUE;
560564
break;
561565
case kKey_W:
562566
case kKey_w:
563567
gVirtualGL->DisableGL(kCULL_FACE);
568+
gVirtualGL->DisableGL(kLIGHTING);
564569
gVirtualGL->PolygonGLMode(kFRONT_AND_BACK, kLINE);
565-
gVirtualGL->SetGLLineWidth(1.5f);
570+
gVirtualGL->ClearGLColor(black[0], black[1], black[2], black[3]);
571+
fScene.SetDrawMode(TGLScene::kWireFrame);
572+
invalidate = kTRUE;
573+
break;
574+
case kKey_T:
575+
case kKey_t:
576+
gVirtualGL->EnableGL(kLIGHTING);
577+
gVirtualGL->EnableGL(kCULL_FACE);
578+
gVirtualGL->PolygonGLMode(kFRONT, kFILL);
579+
gVirtualGL->ClearGLColor(white[0], white[1], white[2], white[3]);
580+
fScene.SetDrawMode(TGLScene::kOutline);
566581
invalidate = kTRUE;
567582
break;
568583
case kKey_Up:

0 commit comments

Comments
 (0)