~ubuntu-branches/ubuntu/quantal/ginkgocadx/quantal

« back to all changes in this revision

Viewing changes to src/cadxcore/vtk/vtkginkgoimageviewer.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2011-11-09 12:29:00 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111109122900-idkd9vvhr31whz8z
Tags: 2.6.0.0~rc-1
* New upstream version
  Closes: #647413
* Rebuild against recent insighttoolkit
  Closes: #648167

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  
3
 
 *  $Id: vtkginkgoimageviewer.cpp 4090 2011-08-25 12:17:45Z tovar $
 
3
 *  $Id: vtkginkgoimageviewer.cpp 4375 2011-11-04 13:49:41Z tovar $
4
4
 *  Ginkgo CADx Project
5
5
 *
6
6
 *  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
76
76
 
77
77
#include <hackimageactor.h>
78
78
 
79
 
#define VTK_GINKGO_ZOOM_MIN 0.5f
 
79
#define VTK_GINKGO_ZOOM_MIN 0.25f
80
80
#define VTK_GINKGO_ZOOM_MAX 200
81
81
 
82
82
extern int vtkrint(double a);
755
755
 
756
756
void vtkGinkgoImageViewer::UpdateOrientation()
757
757
{
758
 
 
759
758
        //GNC::GCS::Timer t;
760
759
        //t.start();
761
760
 
1046
1045
    if (!mantenerVista)
1047
1046
    {
1048
1047
 
1049
 
        UpdateOrientation();
 
1048
                 double focal[3], pos[3];
 
1049
                 GetRelativePositionOfCamera(focal, pos);
 
1050
       UpdateOrientation();
1050
1051
 
1051
1052
        //se comprueba si han cambiado las dimensiones o el spacing
1052
1053
        bool mantenerZoom = true;
1057
1058
            }
1058
1059
        }
1059
1060
        ResetZoom(mantenerZoom);
 
1061
                  if (mantenerZoom) {
 
1062
                          SetRelativePositionOfCamera(focal, pos);
 
1063
                  }
1060
1064
    }
1061
1065
}
1062
1066
 
1817
1821
                e.RollOffset     = eo.RollOffset;
1818
1822
                e.FlipHorizontal = eo.FlipHorizontal;
1819
1823
                e.FlipVertical   = eo.FlipVertical;
 
1824
 
 
1825
                double focal[3], pos[3];
 
1826
                w->GetRelativePositionOfCamera(focal, pos);
 
1827
                this->SetRelativePositionOfCamera(focal,pos);
1820
1828
        }
1821
1829
}
1822
1830
 
1998
2006
 
1999
2007
void vtkGinkgoImageViewer::SyncSetCameraFocalAndPosition(double* /*focal*/, double* /*pos*/)
2000
2008
{
2001
 
        ;
 
2009
        //propagate event
 
2010
        this->InvokeEvent (vtkGinkgoImageViewer::ViewImagePositionChangeEvent, NULL);
 
2011
}
 
2012
 
 
2013
void vtkGinkgoImageViewer::GetRelativePositionOfCamera(double focal[3], double pos[3])
 
2014
{       
 
2015
        //relative position of camera
 
2016
        Propiedades& pr = members->Propiedades;
 
2017
        Pipeline& p = members->Pipeline;
 
2018
 
 
2019
        vtkCamera *camera = p.Renderer->GetActiveCamera();
 
2020
        double focal_c[3], pos_c[3];
 
2021
        camera->GetPosition(pos_c);
 
2022
        camera->GetFocalPoint(focal_c);
 
2023
 
 
2024
        for (int i = 0; i < 3; i++) {
 
2025
                focal[i] = pr.CameraFocalPoint[i] - focal_c[i];
 
2026
                pos[i] = pr.CameraPosition[i] - pos_c[i];
 
2027
        }
 
2028
}
 
2029
 
 
2030
void vtkGinkgoImageViewer::SetRelativePositionOfCamera(const double focal[3], const double pos[3])
 
2031
{
 
2032
        Propiedades& pr = members->Propiedades;
 
2033
        Pipeline& p = members->Pipeline;
 
2034
 
 
2035
        double focal_c[3], pos_c[3];
 
2036
        for (int i = 0; i < 3; i++) {
 
2037
                focal_c[i] = pr.CameraFocalPoint[i] - focal[i];
 
2038
                pos_c[i] = pr.CameraPosition[i] - pos[i];
 
2039
        }
 
2040
 
 
2041
        vtkCamera *camera = p.Renderer->GetActiveCamera();
 
2042
        camera->SetPosition(pos_c);
 
2043
        camera->SetFocalPoint(focal_c);
2002
2044
}
2003
2045
 
2004
2046
void vtkGinkgoImageViewer::SetLookupTable(vtkSmartPointer<vtkScalarsToColors> lut, int idLookupTable)
2047
2089
{
2048
2090
        Pipeline& p = members->Pipeline;
2049
2091
        Estado& e = members->Estado;
2050
 
        p.Renderer->ResetCamera();
2051
 
 
2052
 
        e.InitialParallelScale = p.Renderer->GetActiveCamera()->GetParallelScale();
 
2092
        Propiedades& pr = members->Propiedades;
 
2093
 
 
2094
        double bounds[6];
 
2095
        p.Renderer->ComputeVisiblePropBounds(bounds);
 
2096
        p.Renderer->ResetCamera(members->Pipeline.ImageActor->GetBounds());
 
2097
        double w1 = bounds[1] - bounds[0];
 
2098
        double w2 = bounds[3] - bounds[2];
 
2099
        double w3 = bounds[5] - bounds[4];
 
2100
        double radius = 0.5 * (std::max(w1, std::max(w2, w3)));
 
2101
        vtkCamera *camera = p.Renderer->GetActiveCamera();
 
2102
 
 
2103
        camera->SetParallelScale(radius);
 
2104
 
 
2105
        double focal_c[3], pos_c[3];
 
2106
        camera->GetPosition(pos_c);
 
2107
        camera->GetFocalPoint(focal_c);
 
2108
        //save initial focal point and position
 
2109
        pr.CameraFocalPoint[0] = focal_c[0];
 
2110
        pr.CameraFocalPoint[1] = focal_c[1];
 
2111
        pr.CameraFocalPoint[2] = focal_c[2];
 
2112
 
 
2113
        pr.CameraPosition[0] = pos_c[0];
 
2114
        pr.CameraPosition[1] = pos_c[1];
 
2115
        pr.CameraPosition[2] = pos_c[2];
 
2116
 
 
2117
        e.InitialParallelScale = radius;
2053
2118
        if (mantenerZoom) {
2054
2119
                SetZoom(e.Zoom);
2055
2120
        } else {
2056
2121
                e.Zoom = 1.0;
2057
2122
        }
2058
 
 
2059
 
}
 
2123
}
 
2124
 
 
2125
void vtkGinkgoImageViewer::SetInitialParallelScale(double scale)
 
2126
{
 
2127
        Estado& e = members->Estado;
 
2128
        e.InitialParallelScale = scale;
 
2129
        SetZoom(e.Zoom);
 
2130
}
 
2131
 
2060
2132
 
2061
2133
/** Set the actual zoom factor of the view. */
2062
2134
void vtkGinkgoImageViewer::SetZoom(double factor)