00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkPointSetInteractor.h"
00020 #include "mitkPointSet.h"
00021 #include "mitkPositionEvent.h"
00022 #include "mitkVtkPropRenderer.h"
00023 #include "mitkStateEvent.h"
00024 #include "mitkInteractionConst.h"
00025 #include "mitkGlobalInteraction.h"
00026 #include "mitkPointOperation.h"
00027 #include "mitkTestingMacros.h"
00028
00029 #include <iostream>
00030
00031 const char* POINTSETINTERACTORNAME = "pointsetinteractor";
00032 const char* ONLYMOVEPOINTSETINTERACTORNAME = "onlymovepointsetinteractor";
00033 const char* SEEDPOINTSETINTERACTORNAME = "seedpointsetinteractor";
00034 const char* SINGLEPOINTWITHOUTSHIFTCLICKNAME = "singlepointinteractorwithoutshiftclick";
00035
00039 class mitkPointSetInteractorTestClass {
00040 public:
00041
00042 void TestPointSetInteractor(const char* name, mitk::DataNode* node, mitk::BaseRenderer* sender, int numberOfPointsAllowed)
00043 {
00044 mitk::PointSetInteractor::Pointer interactor = mitk::PointSetInteractor::New(name, node, numberOfPointsAllowed);
00045 MITK_TEST_CONDITION_REQUIRED(interactor.IsNotNull(),"Testing to initialize PointSetInteractor")
00046 std::cout<<"The pattern of the interactor is called: "<<interactor->GetType()<<std::endl;
00047 MITK_TEST_CONDITION_REQUIRED(interactor->GetType() == name,"testing pattern name of interactor");
00048
00049
00050 MITK_TEST_CONDITION_REQUIRED(node != NULL, "error in test! Node == NULL");
00051 mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*>(node->GetData());
00052 MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "error in test! PointSet not set");
00053
00054
00055
00056 mitk::Point3D pos3D;
00057 mitk::Point2D pos2D;
00058 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00059 pos2D[0]= 100; pos2D[0]= 200;
00060
00061 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00062 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking unconnected interactor.");
00063
00064
00065 mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor);
00066
00067
00068 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00069 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking connected interactor by adding a point.");
00070
00071 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing right addition of point.");
00072 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point is selected.");
00073
00074
00075 pos3D.Fill(-100.0);
00076 pos2D.Fill(200.0);
00077 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00078 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) == false,"Testing deselection of a point.");
00079 MITK_TEST_CONDITION_REQUIRED(pointSet->GetNumberOfSelected() == 0,"No selected points.");
00080
00081
00082 mitk::Event* delEvent = new mitk::Event(sender, mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete);
00083 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00084 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking that no unselected point can be deleted.");
00085
00086
00087
00088 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00089 pos2D[0]= 100; pos2D[0]= 200;
00090 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00091 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point is picked.");
00092
00093
00094 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00095 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if the selected point could be delected.");
00096
00097
00098 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00099 pos2D[0]= 11; pos2D[0]= 22;
00100 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00101 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking adding point.");
00102 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point1 is selected.");
00103 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing addition of point.");
00104
00105 pos3D[0]= 111.0; pos3D[1]= 222.0; pos3D[2]= 333.0;
00106 pos2D[0]= 111; pos2D[0]= 222;
00107 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00108 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==2,"Checking adding second point.");
00109 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ==false,"Testing if point1 is deselected.");
00110 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(1) == pos3D,"Testing addition of point.");
00111 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(1) ,"Testing if point2 is selected.");
00112
00113
00114
00115 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00116 pos2D[0]= 11; pos2D[0]= 22;
00117 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00118 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point1 is picked.");
00119
00120
00121 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00122 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking if the picked point1 could be delected.");
00123 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(1) ,"Testing if point2 is now selected.");
00124
00125 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00126 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if point2 could be delected.");
00127
00128
00129 pos3D[0]= 1.0; pos3D[1]= 2.0; pos3D[2]= 3.0;
00130 pos2D[0]= 1; pos2D[0]= 2;
00131 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00132
00133 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00134 pos2D[0]= 11; pos2D[0]= 22;
00135 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00136
00137 pos3D[0]= 111.0; pos3D[1]= 222.0; pos3D[2]= 333.0;
00138 pos2D[0]= 111; pos2D[0]= 222;
00139 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00140
00141 pos3D[0]= 1111.0; pos3D[1]= 2222.0; pos3D[2]= 3333.0;
00142 pos2D[0]= 12; pos2D[0]= 21;
00143 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00144
00145 if (numberOfPointsAllowed>=0)
00146 {
00147 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==(unsigned long)numberOfPointsAllowed,"Checking if only the amount of defined points could be added.");
00148 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(2) ,"Testing if the last point added is selected.");
00149 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(2) != pos3D,"Testing that the last addition didn't work.");
00150 }
00151
00152
00153 pos3D[0]= 1.0; pos3D[1]= 2.0; pos3D[2]= 3.0;
00154 pos2D[0]= 1; pos2D[0]= 2;
00155 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00156 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point1 is selected.");
00157
00158 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00159
00160
00161 pos3D[0]= 0.5; pos3D[1]= 1.0; pos3D[2]= 1.5;
00162 pos2D[0]= 0; pos2D[0]= 1;
00163 this->SendPositionEvent(sender, mitk::Type_MouseMove, mitk::BS_NoButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00164
00165 pos3D[0]= 0.0; pos3D[1]= 0.0; pos3D[2]= 0.0;
00166 pos2D[0]= 0; pos2D[0]= 0;
00167 this->SendPositionEvent(sender, mitk::Type_MouseMove, mitk::BS_NoButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00168
00169
00170 this->SendPositionEvent(sender, mitk::Type_MouseButtonRelease, mitk::BS_LeftButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00171
00172 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing movement of point.");
00173
00174 if (numberOfPointsAllowed>=0)
00175 {
00176
00177 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00178 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==2,"Checking if point3 could be delected.");
00179 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00180 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking if point2 could be delected.");
00181 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00182 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if point1 could be delected.");
00183 }
00184 else
00185 {
00186
00187 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00188 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==3,"Checking if point4 could be delected.");
00189 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00190 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==2,"Checking if point3 could be delected.");
00191 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00192 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking if point2 could be delected.");
00193 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00194 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if point1 could be delected.");
00195 }
00196
00197 mitk::GlobalInteraction::GetInstance()->RemoveInteractor(interactor);
00198 delete delEvent;
00199 }
00200
00201 void TestOnlyMovePointSetInteractor(const char* name, mitk::DataNode* node, mitk::BaseRenderer* sender, int numberOfPointsAllowed)
00202 {
00203 mitk::PointSetInteractor::Pointer interactor = mitk::PointSetInteractor::New(name, node, numberOfPointsAllowed);
00204 MITK_TEST_CONDITION_REQUIRED(interactor.IsNotNull(),"Testing to initialize PointSetInteractor")
00205 std::cout<<"The pattern of the interactor is called: "<<interactor->GetType()<<std::endl;
00206 MITK_TEST_CONDITION_REQUIRED(interactor->GetType() == name,"testing pattern name of interactor");
00207
00208 MITK_TEST_CONDITION_REQUIRED(node != NULL, "error in test! Node == NULL");
00209 mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*>(node->GetData());
00210 MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "error in test! PointSet not set");
00211
00212
00213 mitk::Point3D pos3D;
00214 mitk::Point2D pos2D;
00215 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00216 pos2D[0]= 10; pos2D[0]= 20;
00217 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00218 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking unconnected interactor.");
00219
00220
00221 mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor);
00222
00223
00224 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00225 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Check to add a point.");
00226
00227
00228 mitk::PointSet::Pointer newPointSet = mitk::PointSet::New();
00229
00230
00231 int timestep = 0;
00232 int index = 0;
00233 mitk::PointOperation* doOp = new mitk::PointOperation( mitk::OpINSERT, timestep, pos3D, index);
00234 newPointSet->ExecuteOperation(doOp);
00235
00236
00237 pos3D[0]= 100.0; pos3D[1]= 200.0; pos3D[2]= 300.0;
00238 pos2D[0]= 100; pos2D[0]= 200;
00239 index = 1;
00240 mitk::PointOperation* secondDoOp = new mitk::PointOperation( mitk::OpINSERT, timestep, pos3D, index);
00241 newPointSet->ExecuteOperation(secondDoOp);
00242
00243
00244 node->SetData(newPointSet);
00245 pointSet = dynamic_cast<mitk::PointSet*>(node->GetData());
00246 MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "error in test! new PointSet not set");
00247
00248
00249 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints() == 2,"Testing new data.");
00250
00251
00252
00253
00254
00255 mitk::Event* delEvent = new mitk::Event(sender, mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete);
00256 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00257 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==2,"Checking that no point can be deleted.");
00258 delete delEvent;
00259
00260
00261 pos3D.Fill(-100.0);
00262 pos2D.Fill(200.0);
00263 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00264 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(1) == false,"Testing deselection of a point.");
00265 MITK_TEST_CONDITION_REQUIRED(pointSet->GetNumberOfSelected() == 0,"No selected points.");
00266
00267
00268 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00269 pos2D[0]= 10; pos2D[0]= 20;
00270 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00271 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point is picked.");
00272
00273
00274 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00275
00276
00277 pos3D[0]= 0.5; pos3D[1]= 1.0; pos3D[2]= 1.5;
00278 pos2D[0]= 0; pos2D[0]= 1;
00279 this->SendPositionEvent(sender, mitk::Type_MouseMove, mitk::BS_NoButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00280
00281 pos3D[0]= 0.0; pos3D[1]= 0.0; pos3D[2]= 0.0;
00282 pos2D[0]= 0; pos2D[0]= 0;
00283 this->SendPositionEvent(sender, mitk::Type_MouseMove, mitk::BS_NoButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00284
00285
00286 this->SendPositionEvent(sender, mitk::Type_MouseButtonRelease, mitk::BS_LeftButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00287
00288 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing movement of point.");
00289
00290 mitk::GlobalInteraction::GetInstance()->RemoveInteractor(interactor);
00291 }
00292
00293
00294 void TestSeedPointSetInteractor(const char* name, mitk::DataNode* node, mitk::BaseRenderer* sender)
00295 {
00296 mitk::PointSetInteractor::Pointer interactor = mitk::PointSetInteractor::New(name, node);
00297 MITK_TEST_CONDITION_REQUIRED(interactor.IsNotNull(),"Testing to initialize PointSetInteractor")
00298 std::cout<<"The pattern of the interactor is called: "<<interactor->GetType()<<std::endl;
00299 MITK_TEST_CONDITION_REQUIRED(interactor->GetType() == name,"testing pattern name of interactor");
00300
00301
00302 MITK_TEST_CONDITION_REQUIRED(node != NULL, "error in test! Node == NULL");
00303 mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*>(node->GetData());
00304 MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "error in test! PointSet not set");
00305
00306
00307
00308 mitk::Point3D pos3D;
00309 mitk::Point2D pos2D;
00310 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00311 pos2D[0]= 10; pos2D[0]= 20;
00312
00313 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00314 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking unconnected interactor.");
00315
00316
00317 mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor);
00318
00319
00320 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00321 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking connected interactor by adding a point.");
00322
00323 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing right addition of point.");
00324 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point is selected.");
00325
00326
00327 pos3D.Fill(-100.0);
00328 pos2D.Fill(200.0);
00329 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00330 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) == false,"Testing deselection of a point.");
00331 MITK_TEST_CONDITION_REQUIRED(pointSet->GetNumberOfSelected() == 0,"No selected points.");
00332
00333
00334 mitk::Event* delEvent = new mitk::Event(sender, mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete);
00335 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00336 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking that no unselected point can be deleted.");
00337
00338
00339
00340 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00341 pos2D[0]= 10; pos2D[0]= 20;
00342 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00343 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing picking point.");
00344
00345
00346 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00347 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if the selected point could be delected.");
00348
00349
00350 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00351 pos2D[0]= 11; pos2D[0]= 22;
00352 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00353 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking adding point.");
00354 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point1 is selected.");
00355 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing addition of point.");
00356
00357 pos3D[0]= 111.0; pos3D[1]= 222.0; pos3D[2]= 333.0;
00358 pos2D[0]= 111; pos2D[0]= 222;
00359 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00360 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking that only one point remains in pointset.");
00361 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing addition of point.");
00362 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ==true,"Testing if point is selected.");
00363
00364
00365 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00366 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if the point could be delected.");
00367
00368 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00369 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking Sending Delete again.");
00370
00371
00372 pos3D[0]= 1.0; pos3D[1]= 2.0; pos3D[2]= 3.0;
00373 pos2D[0]= 1; pos2D[0]= 2;
00374 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00375
00376 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00377 pos2D[0]= 11; pos2D[0]= 22;
00378 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00379
00380 pos3D[0]= 111.0; pos3D[1]= 222.0; pos3D[2]= 333.0;
00381 pos2D[0]= 111; pos2D[0]= 222;
00382 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
00383
00384 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking if only one point could be added.");
00385 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing if the last point was inserted.");
00386 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if the last point added is selected.");
00387
00388
00389 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00390
00391
00392 pos3D[0]= 0.5; pos3D[1]= 1.0; pos3D[2]= 1.5;
00393 pos2D[0]= 0; pos2D[0]= 1;
00394 this->SendPositionEvent(sender, mitk::Type_MouseMove, mitk::BS_NoButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00395
00396 pos3D[0]= 0.0; pos3D[1]= 0.0; pos3D[2]= 0.0;
00397 pos2D[0]= 0; pos2D[0]= 0;
00398 this->SendPositionEvent(sender, mitk::Type_MouseMove, mitk::BS_NoButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00399
00400
00401 this->SendPositionEvent(sender, mitk::Type_MouseButtonRelease, mitk::BS_LeftButton, mitk::BS_LeftButton, mitk::Key_none, pos2D, pos3D);
00402
00403 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing movement of point.");
00404
00405
00406
00407
00408 mitk::GlobalInteraction::GetInstance()->RemoveInteractor(interactor);
00409 delete delEvent;
00410 }
00411
00412
00413 void TestSinglePointSetInteractorWithoutShiftClick(const char* name, mitk::DataNode* node, mitk::BaseRenderer* sender)
00414 {
00415 mitk::PointSetInteractor::Pointer interactor = mitk::PointSetInteractor::New(name, node);
00416 MITK_TEST_CONDITION_REQUIRED(interactor.IsNotNull(),"Testing to initialize PointSetInteractor")
00417 std::cout<<"The pattern of the interactor is called: "<<interactor->GetType()<<std::endl;
00418 MITK_TEST_CONDITION_REQUIRED(interactor->GetType() == name,"testing pattern name of interactor");
00419
00420
00421 MITK_TEST_CONDITION_REQUIRED(node != NULL, "error in test! Node == NULL");
00422 mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*>(node->GetData());
00423 MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "error in test! PointSet not set");
00424
00425
00426
00427 mitk::Point3D pos3D;
00428 mitk::Point2D pos2D;
00429 pos3D[0]= 10.0; pos3D[1]= 20.0; pos3D[2]= 30.0;
00430 pos2D[0]= 10; pos2D[0]= 20;
00431
00432 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00433 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking unconnected interactor.");
00434
00435
00436 mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor);
00437
00438
00439 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00440 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking connected interactor by adding a point.");
00441
00442 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing right addition of point.");
00443 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point is selected.");
00444
00445
00446 mitk::Event* delEvent = new mitk::Event(sender, mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete);
00447 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00448 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking deleting point.");
00449
00450
00451 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00452 pos2D[0]= 11; pos2D[0]= 22;
00453 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00454 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking adding point.");
00455 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if point1 is selected.");
00456 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing addition of point.");
00457
00458 pos3D[0]= 111.0; pos3D[1]= 222.0; pos3D[2]= 333.0;
00459 pos2D[0]= 111; pos2D[0]= 222;
00460 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00461 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking that only one point remains in pointset.");
00462 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing addition of point.");
00463 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ==true,"Testing if point is selected.");
00464
00465
00466 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00467 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if the point could be delected.");
00468
00469 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent);
00470 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking Sending Delete again.");
00471
00472
00473 pos3D[0]= 1.0; pos3D[1]= 2.0; pos3D[2]= 3.0;
00474 pos2D[0]= 1; pos2D[0]= 2;
00475 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00476
00477 pos3D[0]= 11.0; pos3D[1]= 22.0; pos3D[2]= 33.0;
00478 pos2D[0]= 11; pos2D[0]= 22;
00479 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00480
00481 pos3D[0]= 111.0; pos3D[1]= 222.0; pos3D[2]= 333.0;
00482 pos2D[0]= 111; pos2D[0]= 222;
00483 this->SendPositionEvent(sender, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none, pos2D, pos3D);
00484
00485 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==1,"Checking if only one point could be added.");
00486 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPoint(0) == pos3D,"Testing if the last point was inserted.");
00487 MITK_TEST_CONDITION_REQUIRED(pointSet->GetSelectInfo(0) ,"Testing if the last point added is selected.");
00488
00489
00490 mitk::GlobalInteraction::GetInstance()->RemoveInteractor(interactor);
00491 delete delEvent;
00492 }
00493
00494 private:
00495
00496 void SendPositionEvent(mitk::BaseRenderer* sender, int type, int button, int buttonState, int key, const mitk::Point2D& displPosition, const mitk::Point3D& worldPosition)
00497 {
00498 mitk::Event *posEvent = new mitk::PositionEvent(sender, type, button, buttonState, key, displPosition, worldPosition);
00499 mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(posEvent);
00500 delete posEvent;
00501 }
00502
00503 };
00504
00505
00506
00507 int mitkPointSetInteractorTest(int , char* [])
00508 {
00509 MITK_TEST_BEGIN("PointSetInteractor")
00510
00511
00512 mitk::GlobalInteraction::GetInstance()->Initialize("global");
00513
00514
00515 mitk::PointSet::Pointer pointSet = mitk::PointSet::New();
00516 mitk::DataNode::Pointer node = mitk::DataNode::New();
00517
00518
00519
00520
00521 mitk::RenderingManager::Pointer myRenderingManager = mitk::RenderingManager::New();
00522 myRenderingManager->SetGlobalInteraction(mitk::GlobalInteraction::GetInstance());
00523 vtkRenderWindow* vtkRenWin = vtkRenderWindow::New();
00524 mitk::VtkPropRenderer::Pointer sender = mitk::VtkPropRenderer::New("testingBR", vtkRenWin, myRenderingManager);
00525 vtkRenWin->Delete();
00526
00527
00528 node->SetData(pointSet);
00529
00530
00531 MITK_TEST_CONDITION_REQUIRED(pointSet->GetPointSet()->GetNumberOfPoints()==0,"Checking if pointset is empty.");
00532
00533
00534 mitkPointSetInteractorTestClass* test = new mitkPointSetInteractorTestClass();
00535
00536
00537 MITK_TEST_OUTPUT(<<"--------Testing "<<POINTSETINTERACTORNAME<<" with max 3 points--------");
00538 test->TestPointSetInteractor(POINTSETINTERACTORNAME, node, sender, 3);
00539
00540 pointSet = mitk::PointSet::New();
00541 node = mitk::DataNode::New();
00542 node->SetData(pointSet);
00543
00544
00545 MITK_TEST_OUTPUT(<<"--------Testing "<<POINTSETINTERACTORNAME<<" with unlimited points --------");
00546 test->TestPointSetInteractor(POINTSETINTERACTORNAME, node, sender, -1);
00547
00548 pointSet = mitk::PointSet::New();
00549 node = mitk::DataNode::New();
00550 node->SetData(pointSet);
00551
00552
00553 MITK_TEST_OUTPUT(<<"--------Testing "<<ONLYMOVEPOINTSETINTERACTORNAME<<" with unlimited points --------");
00554 test->TestOnlyMovePointSetInteractor(ONLYMOVEPOINTSETINTERACTORNAME, node, sender, -1);
00555
00556 pointSet = mitk::PointSet::New();
00557 node = mitk::DataNode::New();
00558 node->SetData(pointSet);
00559
00560 MITK_TEST_OUTPUT(<<"--------Testing "<<SEEDPOINTSETINTERACTORNAME<<" with one point --------");
00561 test->TestSeedPointSetInteractor(SEEDPOINTSETINTERACTORNAME, node, sender);
00562
00563 pointSet = mitk::PointSet::New();
00564 node = mitk::DataNode::New();
00565 node->SetData(pointSet);
00566
00567 MITK_TEST_OUTPUT(<<"--------Testing "<<SINGLEPOINTWITHOUTSHIFTCLICKNAME<<" with one point --------");
00568 test->TestSinglePointSetInteractorWithoutShiftClick(SINGLEPOINTWITHOUTSHIFTCLICKNAME, node, sender);
00569
00570 MITK_TEST_END()
00571 }