ctkVTKAbstractMatrixWidget.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 // Qt includes
00022 #include <QDebug>
00023 #include <QVector>
00024 
00025 // CTK includes
00026 #include "ctkVTKAbstractMatrixWidget_p.h"
00027 #include "ctkVTKAbstractMatrixWidget.h"
00028 
00029 // VTK includes
00030 #include <vtkMatrix4x4.h>
00031 
00032 // --------------------------------------------------------------------------
00033 ctkVTKAbstractMatrixWidgetPrivate::ctkVTKAbstractMatrixWidgetPrivate()
00034   :QObject(0) // will be reparented in init()
00035 {
00036 }
00037 
00038 void ctkVTKAbstractMatrixWidgetPrivate::init()
00039 {
00040   CTK_P(ctkVTKAbstractMatrixWidget);
00041   this->setParent(p);
00042   this->updateMatrix();
00043 }
00044 
00045 // --------------------------------------------------------------------------
00046 void ctkVTKAbstractMatrixWidgetPrivate::setMatrix(vtkMatrix4x4* matrixVariable)
00047 {
00048   qvtkReconnect(this->Matrix.GetPointer(), matrixVariable, 
00049                 vtkCommand::ModifiedEvent, this, SLOT(updateMatrix()));
00050 
00051   this->Matrix = matrixVariable;
00052   this->updateMatrix();
00053 }
00054 
00055 // --------------------------------------------------------------------------
00056 vtkMatrix4x4* ctkVTKAbstractMatrixWidgetPrivate::matrix() const
00057 {
00058   return this->Matrix;
00059 }
00060 
00061 // --------------------------------------------------------------------------
00062 void ctkVTKAbstractMatrixWidgetPrivate::updateMatrix()
00063 {
00064   CTK_P(ctkVTKAbstractMatrixWidget);
00065   // if there is no transform to show/edit, disable the widget
00066   p->setEnabled(this->Matrix != 0);
00067 
00068   if (this->Matrix == 0)
00069     {
00070     p->reset();
00071     return;
00072     }
00073   QVector<double> vector;
00074   //todo: fasten the loop
00075   for (int i=0; i < 4; i++)
00076     {
00077     for (int j=0; j < 4; j++)
00078       {
00079       vector.append(this->Matrix->GetElement(i,j)); 
00080       }
00081     }
00082   p->setVector( vector );
00083 }
00084 
00085 // --------------------------------------------------------------------------
00086 ctkVTKAbstractMatrixWidget::ctkVTKAbstractMatrixWidget(QWidget* parentVariable) : Superclass(parentVariable)
00087 {
00088   CTK_INIT_PRIVATE(ctkVTKAbstractMatrixWidget);
00089   ctk_d()->init();
00090 }
00091 
00092 // --------------------------------------------------------------------------
00093 vtkMatrix4x4* ctkVTKAbstractMatrixWidget::matrix()const
00094 {
00095   CTK_D(const ctkVTKAbstractMatrixWidget);
00096   return d->matrix();
00097 }
00098 
00099 // --------------------------------------------------------------------------
00100 void ctkVTKAbstractMatrixWidget::setMatrixInternal(vtkMatrix4x4* matrixVariable)
00101 {
00102   CTK_D(ctkVTKAbstractMatrixWidget);
00103   d->setMatrix(matrixVariable);
00104 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1