summaryrefslogtreecommitdiff
path: root/src/Select3D/Select3D_SensitiveTriangulation.cxx
blob: 377c9ad420941f67884342a70d44c043f15c2a3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
// File:	Select3D_SensitiveTriangulation.cxx
// Created:	Thu May 15 17:47:05 1997
// Author:	Robert COUBLANC
//		<rob@robox.paris1.matra-dtv.fr>
//Modified      Thur Apr 09 98 by rob : No more computation of free edges.
//                                      fix bug on Compute Depth (don't forget
//                                      Location...)

#define BUC60858	//GG 27/03/01 Avoid to crash when selecting
//			a triangle containing confused or aligned points.

#include <Select3D_SensitiveTriangulation.ixx>
#include <gp_Pnt2d.hxx>
#include <Poly.hxx>
#include <Poly_Connect.hxx>
#include <CSLib_Class2d.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>


static Standard_Integer S3D_NumberOfFreeEdges(const Handle(Poly_Triangulation)& Trg)
{
  Standard_Integer nFree = 0;
  Poly_Connect pc(Trg);
  Standard_Integer t[3];
  Standard_Integer i,j;
  for (i = 1; i <= Trg->NbTriangles(); i++) {
    pc.Triangles(i,t[0],t[1],t[2]);
    for (j = 0; j < 3; j++)
      if (t[j] == 0) nFree++;
  }
  return nFree;
}
static Standard_Boolean S3D_STriangul_NearSegment (const gp_XY& p0, const gp_XY& p1, const gp_XY& TheP,
                                                   const Standard_Real aTol, Standard_Real& aDMin)
{
  Bnd_Box2d B;
  B.SetVoid();
  B.Set(p0);
  B.Update(p1.X(),p1.Y());
  B.Enlarge(aTol*3);
  if(B.IsOut(TheP)) return Standard_False;

  gp_XY V01(p1);V01-=p0;
  gp_XY Vec(TheP);Vec -= p0;

  Standard_Real u = Vec*V01.Normalized();
  if(u<-aTol) return Standard_False;
  Standard_Real u1 = u-aTol;
  Standard_Real modmod = V01.SquareModulus();
  if(u1*u1> modmod) return Standard_False;

  gp_XY N01 (-V01.Y(),V01.X());
  N01.Normalize();
  aDMin = Abs (Vec * N01);
  return aDMin <= aTol;
}

// static Standard_Real S3D_SquareDistanceFromEdge(gp_Pnt2d PCur,
// 						gp_Pnt2d PEdg1,
// 						gp_Pnt2d PEdg2,
// 						const Standard_Real TolTol)
// {
//   gp_XY VEdg (PEdg1.XY());
//   gp_XY VCur (PEdg1.XY());
//   VEdg-= PEdg2.XY();
//   VCur-=PCur.XY();
//   Standard_Real long1 = VEdg.SquareModulus();

//   if(long1<=TolTol)
//     return VCur.SquareModulus();
//   Standard_Real Val = VEdg^VCur;
//   return Val*Val/long1;

// }

static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1,
				     const Standard_Integer e2,
				     const Standard_Integer N1,
				     const Standard_Integer N2,
				     const Standard_Integer N3)
{
  Standard_Integer bid1  = (e1 == N1) ? N1 : ((e1 == N2) ? N2 : ( e1==N3 ? N3 : 0));
  if(bid1==0) return Standard_False;
  Standard_Integer bid2  = (e2 == N1) ? N1 : ((e2 == N2) ? N2 : ( e2==N3 ? N3 : 0));

  if(bid2==0 || bid2 ==bid1) return Standard_False;
  return Standard_True;
}



//=======================================================================
//function : Select3D_SensitiveTriangulation
//purpose  :
//=======================================================================

Select3D_SensitiveTriangulation::
Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
				const Handle(Poly_Triangulation)& Trg,
				const TopLoc_Location& Loc,
				const Standard_Boolean InteriorFlag):
				Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg),
myiniloc(Loc),
myIntFlag(InteriorFlag),
myNodes2d(1,Trg->NbNodes()),
myDetectedTr(-1)
{
  // calculate free edges and cdg 3d of the triangulation:
  // This code should have been integrated in poly_triangulation...

  Standard_Integer fr = 1;
  const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
  const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
  Standard_Integer nbTriangles (myTriangul->NbTriangles());
  gp_XYZ cdg(0,0,0);
  Standard_Integer n[3];
  
  // to find connections in case when the border is not concerned...
  if(!myIntFlag){
    myFreeEdges = new TColStd_HArray1OfInteger(1,2*S3D_NumberOfFreeEdges(Trg));
    TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
    Poly_Connect pc(myTriangul);
    Standard_Integer t[3];
    Standard_Integer i,j;
    for ( i = 1; i <= nbTriangles; i++) {
      pc.Triangles(i,t[0],t[1],t[2]);
      triangles(i).Get(n[0],n[1],n[2]);
      cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
      for (j = 0; j < 3; j++) {
	Standard_Integer k = (j+1) % 3;
	if (t[j] == 0) {
	  FreeE(fr)  = n[j];
	  FreeE(fr+1)= n[k];
	  fr += 2;
	}
      }
    }
  }
  else{
    for (Standard_Integer i = 1; i <= nbTriangles; i++) {
      triangles(i).Get(n[0],n[1],n[2]);
      cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
    }
  }


  if(nbTriangles!=0) cdg /= nbTriangles;
  myCDG3D = gp_Pnt(cdg);

  ComputeTotalTrsf();

  if(myTrsf.Form()!=gp_Identity)
    myCDG3D.Transform(myTrsf);
}


//=======================================================================
//function : Select3D_SensitiveTriangulation
//purpose  :
//=======================================================================
Select3D_SensitiveTriangulation::
Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
				const Handle(Poly_Triangulation)& Trg,
				const TopLoc_Location& Loc,
				const Handle(TColStd_HArray1OfInteger)& FreeEdges,
				const gp_Pnt& TheCDG,
				const Standard_Boolean InteriorFlag):
Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg),
myiniloc(Loc),
myCDG3D(TheCDG),
myFreeEdges(FreeEdges),
myIntFlag(InteriorFlag),
myNodes2d(1,Trg->NbNodes()),
myDetectedTr(-1)
{
}
//=======================================================================
//function : Project
//purpose  :
//=======================================================================

void Select3D_SensitiveTriangulation::Project(const Handle(Select3D_Projector)& aPrj)
{
  Select3D_SensitiveEntity::Project(aPrj); // to set the field last proj...

  mybox2d.SetVoid();
  const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();

  gp_Pnt2d ProjPT;

  for(Standard_Integer I=1;I<=myTriangul->NbNodes();I++){
    if(myTrsf.Form()!=gp_Identity)
      aPrj->Project(Nodes(I).Transformed(myTrsf),ProjPT);
    else
      aPrj->Project(Nodes(I),ProjPT);

    myNodes2d.SetValue(I,ProjPT);
    mybox2d.Add(ProjPT);
  }

  aPrj->Project(myCDG3D,myCDG2D);
}

//=======================================================================
//function : Areas
//purpose  :
//=======================================================================

void Select3D_SensitiveTriangulation::Areas(SelectBasics_ListOfBox2d& boxes)
{
  boxes.Append(mybox2d);
}

//=======================================================================
//function : Matches
//purpose  :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real X,
							  const Standard_Real Y,
							  const Standard_Real aTol,
							  Standard_Real& DMin)
{
  // get view direction (necessary for calculation of depth) from field mylastprj of the base class
  if (mylastprj.IsNull())
    return Standard_False;

  DMin = Precision::Infinite();
  gp_XY BidPoint(X,Y);
  myDetectedTr = -1;
  const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();

  // it is checked if we are inside the triangle 2d.
  if(myIntFlag)
  {
    gp_Lin EyeLine = mylastprj->Shoot(X,Y);
    if ( myTrsf.Form()!=gp_Identity )
      EyeLine.Transform (myTrsf.Inverted());

    Standard_Real aMinDepth = Precision::Infinite();
    const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
    for (Standard_Integer itr=1; itr<=myTriangul->NbTriangles(); itr++)
    {
      Standard_Integer n1,n2,n3;
      triangles(itr).Get(n1,n2,n3);
      const gp_XY& aPnt2d1 = myNodes2d(n1).XY();
      const gp_XY& aPnt2d2 = myNodes2d(n2).XY();
      const gp_XY& aPnt2d3 = myNodes2d(n3).XY();
      gp_XY aUV;
      Standard_Real aDistSquare = Poly::PointOnTriangle (aPnt2d1, aPnt2d2, aPnt2d3, BidPoint, aUV);
      if ( aDistSquare > aTol * aTol )
        continue;

      // compute depth on this triangle
      Standard_Real aDepth1 = ElCLib::Parameter (EyeLine, Nodes(n1));
      Standard_Real aDepth2 = ElCLib::Parameter (EyeLine, Nodes(n2));
      Standard_Real aDepth3 = ElCLib::Parameter (EyeLine, Nodes(n3));
      Standard_Real aDepth = aDepth1 + aUV.X() * (aDepth2 - aDepth1) +
                                       aUV.Y() * (aDepth3 - aDepth1);

      // take triangle with lowest depth and within defined depth interval
      if (aDepth < aMinDepth &&
          aDepth > mylastprj->DepthMin() &&
          aDepth < mylastprj->DepthMax())
      {
        aMinDepth = aDepth;
        myDetectedTr = itr;
        DMin = Sqrt (aDistSquare);
      }
    }
  }
  
  //    Case only Test on Border of the triangulation...
  //   
  else
  {
    //Standard_Integer ifirst;
    TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
    Standard_Integer nn = FreeE.Length(), Node1,Node2;
    //Standard_Real LEdg;
    //Standard_Real DMinDMin,TolTol = aTol*aTol;

    for (Standard_Integer ifri =1; ifri <= nn && myDetectedTr < 0; ifri+=2)
    {
      Node1 = FreeE(ifri);
      Node2 = FreeE(ifri+1);
      if (S3D_STriangul_NearSegment (myNodes2d(Node1).XY(),
                                     myNodes2d(Node2).XY(),
                                     BidPoint, aTol, DMin) )
      {
        for(Standard_Integer itr=1; itr <= myTriangul->NbTriangles(); itr++)
        {
          Standard_Integer n1,n2,n3;
          triangles(itr).Get(n1,n2,n3);
          if(S3D_IsEdgeIn(Node1,Node2,n1,n2,n3))
          {
            myDetectedTr = itr;
            break; // return first found; selection of closest is not implemented yet
          }
        }
      }
    }
  }
  if ( myDetectedTr <= 0 )
    return Standard_False;

  // compute and validate the depth (::Depth()) along the eyeline
  return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
}


//=======================================================================
//function : Matches
//purpose  :
//=======================================================================

Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real XMin,
							  const Standard_Real YMin,
							  const Standard_Real XMax,
							  const Standard_Real YMax,
							  const Standard_Real aTol)
{
  Bnd_Box2d B;
  B.Update(Min(XMin,XMax)-aTol,
	   Min(YMin,YMax)-aTol,
	   Max(XMin,XMax)+aTol,
	   Max(YMin,YMax)+aTol);

  for(Standard_Integer i=myNodes2d.Lower();i<=myNodes2d.Upper();i++){
    if(B.IsOut(myNodes2d(i)))
      return Standard_False;
  }
  return Standard_True;
}


//=======================================================================
//function : Matches
//purpose  :
//=======================================================================

Standard_Boolean Select3D_SensitiveTriangulation::
Matches (const TColgp_Array1OfPnt2d& aPoly,
	 const Bnd_Box2d& aBox,
	 const Standard_Real aTol)
{
  Standard_Real Umin,Vmin,Umax,Vmax;
  aBox.Get(Umin,Vmin,Umax,Vmax);
  CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);

  for(Standard_Integer j=1;j<=myNodes2d.Length();j++){
    Standard_Integer RES = aClassifier2d.SiDans(myNodes2d(j));
    if(RES!=1) return Standard_False;
  }
  return Standard_True;
}



Standard_Integer Select3D_SensitiveTriangulation::Status (const gp_XY& TheP,
 							  const gp_XY& Proj0,
 							  const gp_XY& Proj1,
 							  const gp_XY& Proj2,
 							  const Standard_Real aTol,
							  Standard_Real& DD) const
{
  return Select3D_SensitiveTriangle::Status(Proj0,Proj1,Proj2,TheP,aTol,DD);
}

//=======================================================================
//function : IsFree
//purpose  :
//=======================================================================

Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer IndexOfTriangle,
							 Standard_Integer& FoundIndex) const
{

  FoundIndex=-1;
  Standard_Integer n[3];
  const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
  triangles(IndexOfTriangle).Get(n[0],n[1],n[2]);
    TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();

  for(Standard_Integer I=1;I<=FreeE.Length() && FoundIndex==-1;I+=2){

    if(FreeE(I) == n[0]){

      if(FreeE(I+1)== n[1] || FreeE(I+1)== n[2]) FoundIndex=I;}
    else if(FreeE(I) == n[1]){
      if(FreeE(I+1)== n[0] || FreeE(I+1)== n[2]) FoundIndex=I;}
    else if(FreeE(I) == n[2]){
      if(FreeE(I+1)== n[0] || FreeE(I+1)== n[1]) FoundIndex=I;}
  }

  return FoundIndex!=-1;
}


//=======================================================================
//function : GetConnected
//purpose  :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangulation::
GetConnected(const TopLoc_Location& aLoc)
{

  Handle(Select3D_SensitiveTriangulation) NiouEnt =
    new Select3D_SensitiveTriangulation(myOwnerId,myTriangul,myiniloc,myFreeEdges,myCDG3D,myIntFlag);

  if(HasLocation()) NiouEnt->SetLocation(Location());
//  TopLoc_Location TheLocToApply = HasLocation() ?  Location()*aLoc : aLoc;
//  if(!TheLocToApply.IsIdentity())
  NiouEnt->UpdateLocation(aLoc);


  return NiouEnt;
}


//=======================================================================
//function : ResetLocation
//purpose  :
//=======================================================================
void Select3D_SensitiveTriangulation::ResetLocation()
{
  Select3D_SensitiveEntity::ResetLocation();
  ComputeTotalTrsf();
}
void Select3D_SensitiveTriangulation::SetLocation(const TopLoc_Location& aLoc)
{
  Select3D_SensitiveEntity::SetLocation(aLoc);
  ComputeTotalTrsf();
}


//=======================================================================
//function : Dump
//purpose  :
//=======================================================================
void Select3D_SensitiveTriangulation::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
  S<<"\tSensitiveTriangulation 3D :"<<endl;
  if(myiniloc.IsIdentity())
    S<<"\t\tNo Initial Location"<<endl;
  else
    S<<"\t\tExisting Initial Location"<<endl;
  if(HasLocation())
    S<<"\t\tExisting Location"<<endl;

  S<<"\t\tNb Triangles : "<<myTriangul->NbTriangles()<<endl;
  S<<"\t\tNb Nodes     : "<<myTriangul->NbNodes()<<endl;
  S<<"\t\tNb Free Edges: "<<myFreeEdges->Length()/2<<endl;

  if(FullDump){
//    S<<"\t\t\tOwner:"<<myOwnerId<<endl;
    Select3D_SensitiveEntity::DumpBox(S,mybox2d);
  }
}

//=======================================================================
//function : ComputeDepth
//purpose  :
//=======================================================================
Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLine) const
{
  if(myDetectedTr==-1) return Precision::Infinite(); // currently not implemented...
  const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
  const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();

  Standard_Integer n1,n2,n3;
  triangles(myDetectedTr).Get(n1,n2,n3);
  gp_Pnt P[3]={Nodes(n1),Nodes(n2),Nodes(n3)};

  if(myTrsf.Form()!=gp_Identity){
    for(Standard_Integer i =0;i<=2;i++){
      P[i].Transform(myTrsf);
    }
  }
  
  // formula calculate the parameter of the point on the intersection
  // t = (P1P2 ^P1P3)* OP1  / ((P1P2^P1P3)*Dir)
  Standard_Real prof(Precision::Infinite());
  gp_Pnt Oye  = EyeLine.Location(); // origin of the target line eye/point...
  gp_Dir Dir  = EyeLine.Direction();

  gp_Vec Vtr[3];
  for(Standard_Integer i=0;i<=2;i++)
    Vtr[i] = gp_Vec(P[i%3],P[(i+1)%3]);
  Vtr[2] = -Vtr[2];
  
  // remove singular cases immediately...
  Standard_Integer SingularCase(-1);
  if(Vtr[0].SquareMagnitude()<= Precision::Confusion())
    SingularCase = 0;
  if(Vtr[1].SquareMagnitude()<= Precision::Confusion())
    SingularCase = (SingularCase == -1) ? 1 : 2;
#ifdef BUC60858
  if(Vtr[2].SquareMagnitude()<= Precision::Confusion())
    if( SingularCase < 0 ) SingularCase = 1;
#endif
  
  // 3 pts mixed...
  if(SingularCase ==2){
    prof= ElCLib::Parameter(EyeLine,P[0]);
    return prof;
  }

  if(SingularCase!=0)
    Vtr[0].Normalize();
  if(SingularCase!=1 &&
     SingularCase!=2)
    Vtr[2].Normalize();
  gp_Vec OPo(Oye,P[0]);
  // 2 points mixed... the intersection between the segment and the target line eye/point.
  // 
  if(SingularCase!=-1){
    gp_Vec V = SingularCase==0 ? Vtr[2] : Vtr[0];
    gp_Vec Det = Dir^V;
    gp_Vec VSM = OPo^V;
    if(Det.X()> Precision::Confusion())
      prof = VSM.X()/Det.X();
    else if (Det.Y()> Precision::Confusion())
      prof = VSM.Y()/Det.Y();
    else if(Det.Z()> Precision::Confusion())
      prof = VSM.Z()/Det.Z();
  }
  else{

    Standard_Real val1 = OPo.DotCross(Vtr[0],Vtr[2]);
    Standard_Real val2 = Dir.DotCross(Vtr[0],Vtr[2]);

    if(Abs(val2)>Precision::Confusion())
      prof =val1/val2;
  }
  if (prof==Precision::Infinite()){
    prof= ElCLib::Parameter(EyeLine,P[0]);
    prof = Min (prof, ElCLib::Parameter(EyeLine,P[1]));
    prof = Min (prof, ElCLib::Parameter(EyeLine,P[2]));
  }

  return prof;
}

//=======================================================================
//function : DetectedTriangle
//purpose  :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1,
								   gp_Pnt& P2,
								   gp_Pnt& P3) const
{
  if(myDetectedTr==-1) return Standard_False; // currently not implemented...
  const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
  const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
  Standard_Integer n1,n2,n3;
  triangles(myDetectedTr).Get(n1,n2,n3);

  P1 = Nodes(n1);
  P2 = Nodes(n2);
  P3 = Nodes(n3);
  if(myTrsf.Form()!=gp_Identity){
    P1.Transform(myTrsf);
    P2.Transform(myTrsf);
    P3.Transform(myTrsf);
  }

  return Standard_True;
}

//=============================================================================
// Function : DetectedTriangle2d
// Purpose  :
//=============================================================================
Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle2d(
  gp_Pnt2d& P1, gp_Pnt2d& P2, gp_Pnt2d& P3) const
{
  if(myDetectedTr==-1) 
    return Standard_False; //  currently not implemented...
  const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
  Standard_Integer n1,n2,n3;
  triangles( myDetectedTr ).Get(n1,n2,n3);

  int aLower = myNodes2d.Lower();
  int anUpper = myNodes2d.Upper();
  if ( n1 >= aLower && n1 <= anUpper &&
       n2 >= aLower && n2 <= anUpper &&
       n3 >= aLower && n3 <= anUpper )
  {
    P1 = myNodes2d.Value( n1 );
    P2 = myNodes2d.Value( n2 );
    P3 = myNodes2d.Value( n3 );
    return Standard_True;
  }
  else
    return Standard_False;

}

void Select3D_SensitiveTriangulation::ComputeTotalTrsf()
{
  Standard_Boolean hasloc = (HasLocation() || !myiniloc.IsIdentity());

  if(hasloc){
    if(myiniloc.IsIdentity())
      myTrsf = Location().Transformation();
    else if(HasLocation()){
      myTrsf = (Location()*myiniloc).Transformation();
    }
    else
      myTrsf = myiniloc.Transformation();
  }
  else{
    gp_Trsf TheId;
    myTrsf = TheId;
  }
}