ROOT logo
// @(#)root/eve:$Id: TEveStraightLineSet.cxx 31234 2009-11-17 14:57:10Z matevz $
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TEveStraightLineSet.h"

#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualPad.h"
#include "TVirtualViewer3D.h"

#include "TRandom.h"
#include "TEveProjectionManager.h"


//==============================================================================
//==============================================================================
// TEveStraightLineSet
//==============================================================================

//______________________________________________________________________________
//
// Set of straight lines with optional markers along the lines.

ClassImp(TEveStraightLineSet);

//______________________________________________________________________________
TEveStraightLineSet::TEveStraightLineSet(const char* n, const char* t):
   TEveElement (),
   TNamed      (n, t),

   fLinePlex      (sizeof(Line_t), 4),
   fMarkerPlex    (sizeof(Marker_t), 8),
   fOwnLinesIds   (kFALSE),
   fOwnMarkersIds (kFALSE),
   fRnrMarkers    (kTRUE),
   fRnrLines      (kTRUE),
   fDepthTest     (kTRUE),
   fLastLine      (0)
{
   // Constructor.

   InitMainTrans();
   fPickable = kTRUE;

   fMainColorPtr = &fLineColor;
   fLineColor    = 4;
   fMarkerColor  = 2;
   fMarkerStyle  = 20;
}

/******************************************************************************/

//______________________________________________________________________________
void TEveStraightLineSet::AddLine(Float_t x1, Float_t y1, Float_t z1,
                                  Float_t x2, Float_t y2, Float_t z2)
{
   // Add a line.

   fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
}

//______________________________________________________________________________
void TEveStraightLineSet::AddMarker(Int_t line, Float_t pos)
{
   // Add a marker for line with given index on relative position pos.

   /*Marker_t* marker = */new (fMarkerPlex.NewAtom()) Marker_t(line, pos);
}

/******************************************************************************/

//______________________________________________________________________________
void TEveStraightLineSet::CopyVizParams(const TEveElement* el)
{
   // Copy visualization parameters from element el.

   const TEveStraightLineSet* m = dynamic_cast<const TEveStraightLineSet*>(el);
   if (m)
   {
      TAttLine::operator=(*m);
      TAttMarker::operator=(*m);
      fRnrMarkers = m->fRnrMarkers;
      fRnrLines   = m->fRnrLines;
      fDepthTest  = m->fDepthTest;
   }

   TEveElement::CopyVizParams(el);
}

//______________________________________________________________________________
void TEveStraightLineSet::WriteVizParams(ostream& out, const TString& var)
{
   // Write visualization parameters.

   TEveElement::WriteVizParams(out, var);

   TString t = "   " + var + "->";
   TAttMarker::SaveMarkerAttributes(out, var);
   TAttLine  ::SaveLineAttributes  (out, var);
   out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
   out << t << "SetRnrLines("   << ToString(fRnrLines)   << ");\n";
   out << t << "SetDepthTest("  << ToString(fDepthTest)  << ");\n";
}

/******************************************************************************/

//______________________________________________________________________________
TClass* TEveStraightLineSet::ProjectedClass(const TEveProjection*) const
{
   // Return class of projected object.
   // Virtual from TEveProjectable.

   return TEveStraightLineSetProjected::Class();
}

/******************************************************************************/

//______________________________________________________________________________
void TEveStraightLineSet::ComputeBBox()
{
   // Compute bounding-box.
   // Virtual from TAttBBox.

   static const TEveException eH("TEveStraightLineSet::ComputeBBox ");
   if(fLinePlex.Size() == 0) {
      BBoxZero();
      return;
   }

   BBoxInit();

   TEveChunkManager::iterator li(fLinePlex);
   while (li.next()) {
      BBoxCheckPoint(((Line_t*)li())->fV1);
      BBoxCheckPoint(((Line_t*)li())->fV2);
   }
}

/******************************************************************************/

//______________________________________________________________________________
void TEveStraightLineSet::Paint(Option_t* /*option*/)
{
   // Paint the line-set.

   static const TEveException eH("TEveStraightLineSet::Paint ");

   TBuffer3D buff(TBuffer3DTypes::kGeneric);

   // Section kCore
   buff.fID           = this;
   buff.fColor        = GetMainColor();
   buff.fTransparency = GetMainTransparency();
   buff.fLocalFrame   = kFALSE;
   RefMainTrans().SetBuffer3D(buff);
   buff.SetSectionsValid(TBuffer3D::kCore);

   Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
   if (reqSections != TBuffer3D::kNone)
      Error(eH, "only direct GL rendering supported.");
}


//==============================================================================
//==============================================================================
// TEveStraightLineSetProjected
//==============================================================================

//______________________________________________________________________________
//
// Projected replica of a TEveStraightLineSet.

ClassImp(TEveStraightLineSetProjected);

//______________________________________________________________________________
TEveStraightLineSetProjected::TEveStraightLineSetProjected() :
   TEveStraightLineSet(), TEveProjected ()
{
   // Constructor.
}

/******************************************************************************/

//______________________________________________________________________________
void TEveStraightLineSetProjected::SetProjection(TEveProjectionManager* mng,
                                                 TEveProjectable* model)
{
   // Set projection manager and model object.

   TEveProjected::SetProjection(mng, model);

   // copy line and marker attributes
   * (TAttMarker*)this = * dynamic_cast<TAttMarker*>(fProjectable);
   * (TAttLine*)  this = * dynamic_cast<TAttLine*>(fProjectable);
}

//______________________________________________________________________________
void TEveStraightLineSetProjected::SetDepthLocal(Float_t d)
{
   // Set depth (z-coordinate) of the projected points.

   SetDepthCommon(d, this, fBBox);

   TEveChunkManager::iterator li(fLinePlex);
   while (li.next())
   {
      TEveStraightLineSet::Line_t& l = * (TEveStraightLineSet::Line_t*) li();
      l.fV1[2] = fDepth;
      l.fV2[2] = fDepth;
   }
}

//______________________________________________________________________________
void TEveStraightLineSetProjected::UpdateProjection()
{
   // Callback that actually performs the projection.
   // Called when projection parameters have been updated.

   TEveProjection&      proj = * fManager->GetProjection();
   TEveStraightLineSet& orig = * dynamic_cast<TEveStraightLineSet*>(fProjectable);

   BBoxClear();

   // Lines
   fLinePlex.Reset(sizeof(Line_t), orig.GetLinePlex().Size());
   Float_t p1[3];
   Float_t p2[3];
   TEveChunkManager::iterator li(orig.GetLinePlex());

   TEveTrans& origTrans = orig.RefMainTrans();
   Double_t s1, s2, s3;
   Double_t x, y, z;
   origTrans.GetScale(s1, s2, s3);
   origTrans.GetPos(x, y, z);

   TEveTrans mx;
   mx.Scale(s1, s2, s3);
   while (li.next())
   {
      Line_t* l = (Line_t*) li();
      p1[0] = l->fV1[0]; p1[1] = l->fV1[1]; p1[2] = l->fV1[2];
      p2[0] = l->fV2[0]; p2[1] = l->fV2[1]; p2[2] = l->fV2[2];
      mx.MultiplyIP(p1);
      mx.MultiplyIP(p2);
      p1[0] += x; p1[1] += y; p1[2] += z;
      p2[0] += x; p2[1] += y; p2[2] += z;
      proj.ProjectPointfv(p1, fDepth);
      proj.ProjectPointfv(p2, fDepth);
      AddLine(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]);
   }

   // Markers
   fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
   TEveChunkManager::iterator mi(orig.GetMarkerPlex());
   while (mi.next())
   {
      Marker_t *m = (Marker_t*) mi();
      Line_t  *lo = (Line_t*) orig.GetLinePlex().Atom(m->fLineID);
      Line_t  *lp = (Line_t*) fLinePlex.Atom(m->fLineID);

      TEveVector t1, d, xx;

      t1.Set(lo->fV1); xx.Set(lo->fV2); xx -= t1; xx *= m->fPos; xx += t1;
      proj.ProjectVector(xx, 0);
      t1.Set(lp->fV1); d.Set(lp->fV2); d -= t1; xx -= t1;

      AddMarker(m->fLineID, d.Dot(xx) / d.Mag2());
   }
}
 TEveStraightLineSet.cxx:1
 TEveStraightLineSet.cxx:2
 TEveStraightLineSet.cxx:3
 TEveStraightLineSet.cxx:4
 TEveStraightLineSet.cxx:5
 TEveStraightLineSet.cxx:6
 TEveStraightLineSet.cxx:7
 TEveStraightLineSet.cxx:8
 TEveStraightLineSet.cxx:9
 TEveStraightLineSet.cxx:10
 TEveStraightLineSet.cxx:11
 TEveStraightLineSet.cxx:12
 TEveStraightLineSet.cxx:13
 TEveStraightLineSet.cxx:14
 TEveStraightLineSet.cxx:15
 TEveStraightLineSet.cxx:16
 TEveStraightLineSet.cxx:17
 TEveStraightLineSet.cxx:18
 TEveStraightLineSet.cxx:19
 TEveStraightLineSet.cxx:20
 TEveStraightLineSet.cxx:21
 TEveStraightLineSet.cxx:22
 TEveStraightLineSet.cxx:23
 TEveStraightLineSet.cxx:24
 TEveStraightLineSet.cxx:25
 TEveStraightLineSet.cxx:26
 TEveStraightLineSet.cxx:27
 TEveStraightLineSet.cxx:28
 TEveStraightLineSet.cxx:29
 TEveStraightLineSet.cxx:30
 TEveStraightLineSet.cxx:31
 TEveStraightLineSet.cxx:32
 TEveStraightLineSet.cxx:33
 TEveStraightLineSet.cxx:34
 TEveStraightLineSet.cxx:35
 TEveStraightLineSet.cxx:36
 TEveStraightLineSet.cxx:37
 TEveStraightLineSet.cxx:38
 TEveStraightLineSet.cxx:39
 TEveStraightLineSet.cxx:40
 TEveStraightLineSet.cxx:41
 TEveStraightLineSet.cxx:42
 TEveStraightLineSet.cxx:43
 TEveStraightLineSet.cxx:44
 TEveStraightLineSet.cxx:45
 TEveStraightLineSet.cxx:46
 TEveStraightLineSet.cxx:47
 TEveStraightLineSet.cxx:48
 TEveStraightLineSet.cxx:49
 TEveStraightLineSet.cxx:50
 TEveStraightLineSet.cxx:51
 TEveStraightLineSet.cxx:52
 TEveStraightLineSet.cxx:53
 TEveStraightLineSet.cxx:54
 TEveStraightLineSet.cxx:55
 TEveStraightLineSet.cxx:56
 TEveStraightLineSet.cxx:57
 TEveStraightLineSet.cxx:58
 TEveStraightLineSet.cxx:59
 TEveStraightLineSet.cxx:60
 TEveStraightLineSet.cxx:61
 TEveStraightLineSet.cxx:62
 TEveStraightLineSet.cxx:63
 TEveStraightLineSet.cxx:64
 TEveStraightLineSet.cxx:65
 TEveStraightLineSet.cxx:66
 TEveStraightLineSet.cxx:67
 TEveStraightLineSet.cxx:68
 TEveStraightLineSet.cxx:69
 TEveStraightLineSet.cxx:70
 TEveStraightLineSet.cxx:71
 TEveStraightLineSet.cxx:72
 TEveStraightLineSet.cxx:73
 TEveStraightLineSet.cxx:74
 TEveStraightLineSet.cxx:75
 TEveStraightLineSet.cxx:76
 TEveStraightLineSet.cxx:77
 TEveStraightLineSet.cxx:78
 TEveStraightLineSet.cxx:79
 TEveStraightLineSet.cxx:80
 TEveStraightLineSet.cxx:81
 TEveStraightLineSet.cxx:82
 TEveStraightLineSet.cxx:83
 TEveStraightLineSet.cxx:84
 TEveStraightLineSet.cxx:85
 TEveStraightLineSet.cxx:86
 TEveStraightLineSet.cxx:87
 TEveStraightLineSet.cxx:88
 TEveStraightLineSet.cxx:89
 TEveStraightLineSet.cxx:90
 TEveStraightLineSet.cxx:91
 TEveStraightLineSet.cxx:92
 TEveStraightLineSet.cxx:93
 TEveStraightLineSet.cxx:94
 TEveStraightLineSet.cxx:95
 TEveStraightLineSet.cxx:96
 TEveStraightLineSet.cxx:97
 TEveStraightLineSet.cxx:98
 TEveStraightLineSet.cxx:99
 TEveStraightLineSet.cxx:100
 TEveStraightLineSet.cxx:101
 TEveStraightLineSet.cxx:102
 TEveStraightLineSet.cxx:103
 TEveStraightLineSet.cxx:104
 TEveStraightLineSet.cxx:105
 TEveStraightLineSet.cxx:106
 TEveStraightLineSet.cxx:107
 TEveStraightLineSet.cxx:108
 TEveStraightLineSet.cxx:109
 TEveStraightLineSet.cxx:110
 TEveStraightLineSet.cxx:111
 TEveStraightLineSet.cxx:112
 TEveStraightLineSet.cxx:113
 TEveStraightLineSet.cxx:114
 TEveStraightLineSet.cxx:115
 TEveStraightLineSet.cxx:116
 TEveStraightLineSet.cxx:117
 TEveStraightLineSet.cxx:118
 TEveStraightLineSet.cxx:119
 TEveStraightLineSet.cxx:120
 TEveStraightLineSet.cxx:121
 TEveStraightLineSet.cxx:122
 TEveStraightLineSet.cxx:123
 TEveStraightLineSet.cxx:124
 TEveStraightLineSet.cxx:125
 TEveStraightLineSet.cxx:126
 TEveStraightLineSet.cxx:127
 TEveStraightLineSet.cxx:128
 TEveStraightLineSet.cxx:129
 TEveStraightLineSet.cxx:130
 TEveStraightLineSet.cxx:131
 TEveStraightLineSet.cxx:132
 TEveStraightLineSet.cxx:133
 TEveStraightLineSet.cxx:134
 TEveStraightLineSet.cxx:135
 TEveStraightLineSet.cxx:136
 TEveStraightLineSet.cxx:137
 TEveStraightLineSet.cxx:138
 TEveStraightLineSet.cxx:139
 TEveStraightLineSet.cxx:140
 TEveStraightLineSet.cxx:141
 TEveStraightLineSet.cxx:142
 TEveStraightLineSet.cxx:143
 TEveStraightLineSet.cxx:144
 TEveStraightLineSet.cxx:145
 TEveStraightLineSet.cxx:146
 TEveStraightLineSet.cxx:147
 TEveStraightLineSet.cxx:148
 TEveStraightLineSet.cxx:149
 TEveStraightLineSet.cxx:150
 TEveStraightLineSet.cxx:151
 TEveStraightLineSet.cxx:152
 TEveStraightLineSet.cxx:153
 TEveStraightLineSet.cxx:154
 TEveStraightLineSet.cxx:155
 TEveStraightLineSet.cxx:156
 TEveStraightLineSet.cxx:157
 TEveStraightLineSet.cxx:158
 TEveStraightLineSet.cxx:159
 TEveStraightLineSet.cxx:160
 TEveStraightLineSet.cxx:161
 TEveStraightLineSet.cxx:162
 TEveStraightLineSet.cxx:163
 TEveStraightLineSet.cxx:164
 TEveStraightLineSet.cxx:165
 TEveStraightLineSet.cxx:166
 TEveStraightLineSet.cxx:167
 TEveStraightLineSet.cxx:168
 TEveStraightLineSet.cxx:169
 TEveStraightLineSet.cxx:170
 TEveStraightLineSet.cxx:171
 TEveStraightLineSet.cxx:172
 TEveStraightLineSet.cxx:173
 TEveStraightLineSet.cxx:174
 TEveStraightLineSet.cxx:175
 TEveStraightLineSet.cxx:176
 TEveStraightLineSet.cxx:177
 TEveStraightLineSet.cxx:178
 TEveStraightLineSet.cxx:179
 TEveStraightLineSet.cxx:180
 TEveStraightLineSet.cxx:181
 TEveStraightLineSet.cxx:182
 TEveStraightLineSet.cxx:183
 TEveStraightLineSet.cxx:184
 TEveStraightLineSet.cxx:185
 TEveStraightLineSet.cxx:186
 TEveStraightLineSet.cxx:187
 TEveStraightLineSet.cxx:188
 TEveStraightLineSet.cxx:189
 TEveStraightLineSet.cxx:190
 TEveStraightLineSet.cxx:191
 TEveStraightLineSet.cxx:192
 TEveStraightLineSet.cxx:193
 TEveStraightLineSet.cxx:194
 TEveStraightLineSet.cxx:195
 TEveStraightLineSet.cxx:196
 TEveStraightLineSet.cxx:197
 TEveStraightLineSet.cxx:198
 TEveStraightLineSet.cxx:199
 TEveStraightLineSet.cxx:200
 TEveStraightLineSet.cxx:201
 TEveStraightLineSet.cxx:202
 TEveStraightLineSet.cxx:203
 TEveStraightLineSet.cxx:204
 TEveStraightLineSet.cxx:205
 TEveStraightLineSet.cxx:206
 TEveStraightLineSet.cxx:207
 TEveStraightLineSet.cxx:208
 TEveStraightLineSet.cxx:209
 TEveStraightLineSet.cxx:210
 TEveStraightLineSet.cxx:211
 TEveStraightLineSet.cxx:212
 TEveStraightLineSet.cxx:213
 TEveStraightLineSet.cxx:214
 TEveStraightLineSet.cxx:215
 TEveStraightLineSet.cxx:216
 TEveStraightLineSet.cxx:217
 TEveStraightLineSet.cxx:218
 TEveStraightLineSet.cxx:219
 TEveStraightLineSet.cxx:220
 TEveStraightLineSet.cxx:221
 TEveStraightLineSet.cxx:222
 TEveStraightLineSet.cxx:223
 TEveStraightLineSet.cxx:224
 TEveStraightLineSet.cxx:225
 TEveStraightLineSet.cxx:226
 TEveStraightLineSet.cxx:227
 TEveStraightLineSet.cxx:228
 TEveStraightLineSet.cxx:229
 TEveStraightLineSet.cxx:230
 TEveStraightLineSet.cxx:231
 TEveStraightLineSet.cxx:232
 TEveStraightLineSet.cxx:233
 TEveStraightLineSet.cxx:234
 TEveStraightLineSet.cxx:235
 TEveStraightLineSet.cxx:236
 TEveStraightLineSet.cxx:237
 TEveStraightLineSet.cxx:238
 TEveStraightLineSet.cxx:239
 TEveStraightLineSet.cxx:240
 TEveStraightLineSet.cxx:241
 TEveStraightLineSet.cxx:242
 TEveStraightLineSet.cxx:243
 TEveStraightLineSet.cxx:244
 TEveStraightLineSet.cxx:245
 TEveStraightLineSet.cxx:246
 TEveStraightLineSet.cxx:247
 TEveStraightLineSet.cxx:248
 TEveStraightLineSet.cxx:249
 TEveStraightLineSet.cxx:250
 TEveStraightLineSet.cxx:251
 TEveStraightLineSet.cxx:252
 TEveStraightLineSet.cxx:253
 TEveStraightLineSet.cxx:254
 TEveStraightLineSet.cxx:255
 TEveStraightLineSet.cxx:256
 TEveStraightLineSet.cxx:257
 TEveStraightLineSet.cxx:258
 TEveStraightLineSet.cxx:259
 TEveStraightLineSet.cxx:260
 TEveStraightLineSet.cxx:261
 TEveStraightLineSet.cxx:262
 TEveStraightLineSet.cxx:263
 TEveStraightLineSet.cxx:264
 TEveStraightLineSet.cxx:265
 TEveStraightLineSet.cxx:266
 TEveStraightLineSet.cxx:267
 TEveStraightLineSet.cxx:268
 TEveStraightLineSet.cxx:269
 TEveStraightLineSet.cxx:270
 TEveStraightLineSet.cxx:271
 TEveStraightLineSet.cxx:272
 TEveStraightLineSet.cxx:273
 TEveStraightLineSet.cxx:274
 TEveStraightLineSet.cxx:275
 TEveStraightLineSet.cxx:276
 TEveStraightLineSet.cxx:277