24 #include <vtkObjectFactory.h>
26 #include "vtkCamera.h"
27 #include "vtkCommand.h"
28 #include "vtkGraphicsFactory.h"
29 #include "vtkHardwareSelector.h"
31 #include "vtkRendererDelegate.h"
32 #include "vtkRenderPass.h"
33 #include "vtkRenderState.h"
34 #include "vtkRenderWindow.h"
35 #include "vtkTexture.h"
48 class axlRendererPrivate
57 qDebug()<<
"axlRenderer::New()";
76 this->Superclass::PrintSelf(os,indent);
362 qDebug()<<
"axlRenderer::ResetCamera ";
367 this->GetActiveCamera();
368 if ( this->ActiveCamera != NULL )
370 this->ActiveCamera->GetViewPlaneNormal(vn);
374 vtkErrorMacro(<<
"Trying to reset non-existant camera");
378 center[0] = (bounds[0] + bounds[1])/2.0;
379 center[1] = (bounds[2] + bounds[3])/2.0;
380 center[2] = (bounds[4] + bounds[5])/2.0;
382 double w1 = bounds[1] - bounds[0];
383 double w2 = bounds[3] - bounds[2];
384 double w3 = bounds[5] - bounds[4];
388 double radius = w1 + w2 + w3;
391 radius = (radius==0)?(1.0):(radius);
394 radius = sqrt(radius)*0.5;
409 double angle=vtkMath::RadiansFromDegrees(this->ActiveCamera->GetViewAngle());
410 double parallelScale=radius;
412 this->ComputeAspect();
414 this->GetAspect(aspect);
418 if(this->ActiveCamera->GetUseHorizontalViewAngle())
420 angle=2.0*atan(tan(angle*0.5)/aspect[0]);
425 if(!this->ActiveCamera->GetUseHorizontalViewAngle())
427 angle=2.0*atan(tan(angle*0.5)*aspect[0]);
430 parallelScale=parallelScale/aspect[0];
433 distance =radius/sin(angle*0.5);
436 vup = this->ActiveCamera->GetViewUp();
437 if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 )
439 vtkWarningMacro(<<
"Resetting view-up since view plane normal is parallel");
440 this->ActiveCamera->SetViewUp(-vup[2], vup[0], vup[1]);
444 this->ActiveCamera->SetFocalPoint(center[0],center[1],center[2]);
445 this->ActiveCamera->SetPosition(center[0]+distance*vn[0],
446 center[1]+distance*vn[1],
447 center[2]+distance*vn[2]);
462 this->ActiveCamera->SetParallelScale(parallelScale);
472 qDebug()<<
"axlRenderer::ResetCamera 2 ";
476 this->ComputeVisiblePropBounds( allBounds );
478 if (!vtkMath::AreBoundsInitialized(allBounds))
480 vtkDebugMacro( <<
"Cannot reset camera!" );
489 this->InvokeEvent(vtkCommand::ResetCameraEvent,
this);
495 double ymin,
double ymax,
496 double zmin,
double zmax)
514 std::cout<<
" reset vtk Camera"<<std::endl;
515 double vn[3], position[3], a, b, c, d;
516 double range[2], dist;
520 if (!vtkMath::AreBoundsInitialized(bounds))
525 this->GetActiveCameraAndResetIfCreated();
526 if ( this->ActiveCamera == NULL )
528 vtkErrorMacro(<<
"Trying to reset clipping range of non-existant camera");
533 this->ActiveCamera->GetViewPlaneNormal(vn);
534 this->ActiveCamera->GetPosition(position);
538 d = -(a*position[0] + b*position[1] + c*position[2]);
541 range[0] = a*bounds[0] + b*bounds[2] + c*bounds[4] + d;
545 for ( k = 0; k < 2; k++ )
547 for ( j = 0; j < 2; j++ )
549 for ( i = 0; i < 2; i++ )
551 dist = a*bounds[i] + b*bounds[2+j] + c*bounds[4+k] + d;
552 range[0] = (dist<range[0])?(dist):(range[0]);
553 range[1] = (dist>range[1])?(dist):(range[1]);
565 range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
566 range[1] = 1.01*range[1] + (range[1] - range[0])*0.5;
569 range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
574 if (!this->NearClippingPlaneTolerance)
576 this->NearClippingPlaneTolerance = 0.01;
577 if (this->RenderWindow)
579 int ZBufferDepth = this->RenderWindow->GetDepthBufferSize();
580 if ( ZBufferDepth > 16 )
582 this->NearClippingPlaneTolerance = 0.001;
590 if (range[0] < this->NearClippingPlaneTolerance*range[1])
592 range[0] = this->NearClippingPlaneTolerance*range[1];
595 this->ActiveCamera->SetClippingRange( range );
604 this->ComputeVisiblePropBounds( allBounds );
616 if (!vtkMath::AreBoundsInitialized(allBounds))
618 vtkDebugMacro( <<
"Cannot reset camera clipping range!" );
627 this->InvokeEvent(vtkCommand::ResetCameraClippingRangeEvent,
this);
void PrintSelf(ostream &os, vtkIndent indent)
void ResetCameraClippingRange()
double angle(axlPoint vCompute, axlPoint vRef, axlPoint normal)