GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBContourManager.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #include "QGoDBContourManager.h"
36 #include "GoDBContourRow.h"
37 #include <iostream>
38 #include <sstream>
39 #include <QMessageBox>
40 #include <QMenu>
41 #include "GoDBContourRow.h"
42 
43 QGoDBContourManager::QGoDBContourManager(int iImgSessionID, QWidget *iparent) :
44  QGoDBTraceManager(), m_ContourContainerInfoForVisu(NULL)
45 {
46  this->SetInfo(iImgSessionID, iparent);
48  this->m_CollectionName, iImgSessionID);
49 }
50 
51 //-------------------------------------------------------------------------
52 
53 //-------------------------------------------------------------------------
55 {
56  if ( this->m_TWContainer )
57  {
58  delete this->m_TWContainer;
59  }
60 }
61 
62 //-------------------------------------------------------------------------
63 
64 //-------------------------------------------------------------------------
66  ContourContainer *iContainerForVisu)
67 {
68  this->SetTracesInfoContainerForVisuTemplate< ContourContainer >(
69  iContainerForVisu, &this->m_ContourContainerInfoForVisu);
70 }
71 
72 //-------------------------------------------------------------------------
73 
74 //-------------------------------------------------------------------------
76 {
77  this->m_TraceName = "contour";
78  this->m_CollectionName = "mesh";
79  this->m_CollectionOf = "None";
80 }
81 
82 //-------------------------------------------------------------------------
83 
84 //-------------------------------------------------------------------------
86  vtkMySQLDatabase *iDatabaseConnector)
87 {
88  this->DisplayInfoAndLoadVisuContainerWithAllTraces< GoDBTWContainerForContourMesh >
89  (this->m_TWContainer, iDatabaseConnector);
90 }
91 
92 //-------------------------------------------------------------------------
93 
94 //-------------------------------------------------------------------------
96  vtkMySQLDatabase *iDatabaseConnector, const std::list<unsigned int> & iListTPs)
97 {
98  this->DisplayInfoAndLoadVisuContainerWithAllTracesForSpecificTPs< ContourMeshContainer >
99  (iDatabaseConnector, this->m_ContourContainerInfoForVisu, iListTPs);
100 }
101 
102 //-------------------------------------------------------------------------
103 
104 //-------------------------------------------------------------------------
106  vtkMySQLDatabase *iDatabaseConnector, const std::list<unsigned int> & iListTPs)
107  {
108  //this->AddInfoInTWAndContainerForVisuForSpecificTPs< ContourMeshContainer >
109  // (iDatabaseConnector, this->m_ContourContainerInfoForVisu, iListTPs);
110 
111  this->AddInfoForContoursInTWForSpecificTPs(iDatabaseConnector, iListTPs);
112  std::list<unsigned int> ListIDs =
114  iDatabaseConnector, iListTPs);
115  std::list<ContourMeshContainer::MultiIndexContainerElementType> list_of_traces =
116  this->m_CollectionOfTraces->
117  GetListStructureFromDB<ContourMeshContainer::MultiIndexContainerElementType>(
118  iDatabaseConnector, this->m_ImgSessionID, ListIDs);
121  }
122 
123  //-------------------------------------------------------------------------
124 
125 //-------------------------------------------------------------------------
127 AddInfoForContoursInTWForSpecificTPs(vtkMySQLDatabase *iDatabaseConnector,
128  const std::list<unsigned int> & iListTPs)
129 {
130  //int IndexShowColumn = this->m_TWContainer->GetIndexShowColumn();
131 
132  /*this->AddInfoForTracesInTWForSpecificTPsTemplate<GoDBTWContainerForContourMesh>(
133  this->m_TWContainer,
134  iDatabaseConnector, Qt::Unchecked, IndexShowColumn );*/
135  //load the container with the traces infos for the TW for the TimePoints contained
136  //in iListTPs:
137  TWContainerType RowContainer =
138  this->m_TWContainer->GetContainerLoadedWithAllFromDB(iDatabaseConnector, iListTPs);
139 
140  this->m_Table->InsertNewRows(RowContainer,
141  this->m_TWContainer->GetIndexForGroupColor(this->m_TraceName),
143  this->m_TraceName,
144  this->m_CollectionName,
145  Qt::Unchecked);
146 }
147 //-------------------------------------------------------------------------
148 
149 //-------------------------------------------------------------------------
150 
152  vtkMySQLDatabase *iDatabaseConnector)
153 
154 {
155  int IndexShowColumn = this->m_TWContainer->GetIndexShowColumn();
156 
157  this->DisplayInfoForAllTracesTemplate< GoDBTWContainerForContourMesh >(
158  this->m_TWContainer, iDatabaseConnector, Qt::Unchecked, IndexShowColumn);
159 }
160 
161 //-------------------------------------------------------------------------
162 
163 //-------------------------------------------------------------------------
165  vtkMySQLDatabase *iDatabaseConnector,
166  const std::list<unsigned int> & iListTPs)
167 {
168  int IndexShowColumn = this->m_TWContainer->GetIndexShowColumn();
169  this->DisplayInfoForTracesForSpecificTPsTemplate< GoDBTWContainerForContourMesh >(
170  this->m_TWContainer, iDatabaseConnector, Qt::Unchecked, iListTPs,
171  IndexShowColumn);
172 }
173 
174 //-------------------------------------------------------------------------
175 
176 //-------------------------------------------------------------------------
178  vtkMySQLDatabase *iDatabaseConnector)
179 {
180  this->DisplayInfoForLastCreatedTraceTemplate< GoDBTWContainerForContourMesh >(
181  this->m_TWContainer, iDatabaseConnector);
182 }
183 
184 //-------------------------------------------------------------------------
185 
186 //-------------------------------------------------------------------------
188  vtkMySQLDatabase *iDatabaseConnector, int iTraceID)
189 {
190  this->DisplayInfoForExistingTraceTemplate< GoDBTWContainerForContourMesh >(
191  this->m_TWContainer, iDatabaseConnector, iTraceID);
192 }
193 
194 //-------------------------------------------------------------------------
195 
196 //-------------------------------------------------------------------------
199  vtkMySQLDatabase *iDatabaseConnector,
200  const std::list<unsigned int> & iListTPs)
201 {
202  this->RemoveTracesFromTWAndContainerForVisuForSpecificTPsTemplate< ContourMeshContainer >
203  (iDatabaseConnector, this->m_ContourContainerInfoForVisu, iListTPs);
204 }
205 
206 //-------------------------------------------------------------------------
207 
208 //-------------------------------------------------------------------------
210 {
213  this->m_CheckedTracesMenu->addAction( tr("ReEdit the checked %1")
214  .arg( this->m_TraceName.c_str() ),
215  this, SLOT( ReEditTrace() ) );
216 }
217 
218 //-------------------------------------------------------------------------
219 
220 //-------------------------------------------------------------------------
222 {
224  tr("Generate a new mesh from checked contours"),
225  this, SLOT( CreateCorrespondingCollection() ) );
226 }
227 
228 //-------------------------------------------------------------------------
229 
230 //-------------------------------------------------------------------------
232 {
234 
237 }
238 
239 //-------------------------------------------------------------------------
240 
241 //-------------------------------------------------------------------------
243  vtkMySQLDatabase *iDatabaseConnector)
244 {
245  return this->UpdateTheTracesColorTemplate< GoDBContourRow, ContourMeshContainer >(
246  iDatabaseConnector, this->m_ContourContainerInfoForVisu);
247 }
248 
249 //-------------------------------------------------------------------------
250 
251 //-------------------------------------------------------------------------
253  int iTCoord,
254  unsigned int iXCoordMin, unsigned int iYCoordMin, unsigned int iZCoordMin,
255  unsigned int iXCoordMax, unsigned int iYCoordMax,
256  unsigned int iZCoordMax, vtkPolyData *iTraceNodes,
257  vtkMySQLDatabase *iDatabaseConnector,
258  unsigned int iMeshID)
259 
260 {
261  //if ( this->m_SelectedCollectionData->first != "Add a new mesh ..."
262  //&& iMeshID != 0)
263  if ( iMeshID != 0 )
264  {
265  iMeshID = ss_atoi< unsigned int >(this->m_SelectedCollectionData->first);
266  }
267  GoDBContourRow NewContour(this->m_ImgSessionID);
268 
269  int NewContourID = this->CreateNewTraceInDBFromVisu< GoDBContourRow >(
270  iXCoordMin, iYCoordMin, iZCoordMin, iTCoord,//*this->m_CurrentTimePoint,
271  iXCoordMax, iYCoordMax, iZCoordMax, iTraceNodes,
272  *this->m_SelectedColorData,
273  iDatabaseConnector, NewContour, iMeshID);
274  // pointer to double has to be deleted after usage...
275  double *rgba = this->GetVectorFromQColor(this->m_SelectedColorData->second);
277  NewContourID, rgba);
278  delete[] rgba;
279 
280  this->DisplayInfoForLastCreatedTrace(iDatabaseConnector);
281  return NewContourID;
282 }
283 
284 //-------------------------------------------------------------------------
285 
286 //-------------------------------------------------------------------------
287 unsigned int QGoDBContourManager::SaveReeditedContourFromVisu(unsigned int iXCoordMin,
288  unsigned int iYCoordMin,
289  unsigned int iZCoordMin,
290  unsigned int iTCoord,
291  unsigned int iXCoordMax,
292  unsigned int iYCoordMax,
293  unsigned int iZCoordMax,
294  vtkPolyData *iContourNodes,
295  vtkMySQLDatabase *iDatabaseConnector)
296 {
297  unsigned int TraceID =
299  GoDBContourRow ReeditedContour;
300 
301  ReeditedContour.SetValuesForSpecificID(TraceID, iDatabaseConnector);
302  this->SetTraceBoundingBoxAndPoints(iXCoordMin, iYCoordMin, iZCoordMin, iTCoord, iXCoordMax,
303  iYCoordMax, iZCoordMax, iContourNodes, iDatabaseConnector,
304  ReeditedContour);
305  ReeditedContour.SaveInDB(iDatabaseConnector);
306  this->DisplayInfoForExistingTrace(iDatabaseConnector, TraceID);
307  return TraceID;
308 }
309 
310 //-------------------------------------------------------------------------
311 
312 //-------------------------------------------------------------------------
314 {
315  std::list< unsigned int > ListCheckedTraces =
317  if ( ListCheckedTraces.empty() )
318  {
319  QMessageBox msgBox;
320  msgBox.setText(
321  tr("Please select the %1 you want to reedit")
322  .arg( this->m_TraceName.c_str() ) );
323  msgBox.exec();
324  }
325  else
326  {
327  if ( ListCheckedTraces.size() != 1 )
328  {
329  QMessageBox msgBox;
330  msgBox.setText(
331  tr("Please select only one %1 to reedit")
332  .arg( this->m_TraceName.c_str() ) );
333  msgBox.exec();
334  }
335  else
336  {
337  emit TraceToReEdit( ListCheckedTraces.front() );
338  }
339  }
340 }
341 
342 //-------------------------------------------------------------------------
343 
344 //-------------------------------------------------------------------------
346  const std::vector< int > & iVectorImportedTraces,
347  vtkMySQLDatabase *iDatabaseConnector)
348 {
351  this->m_TWContainer, iVectorImportedTraces, iDatabaseConnector);
352  //update the visualization and the data from visu in the container for visu:
354  UpdateVisualizationForGivenIDs< std::vector< int > >(
355  iVectorImportedTraces);
356 }
357 
358 //-------------------------------------------------------------------------
359 
360 //-------------------------------------------------------------------------
361 void QGoDBContourManager::DeleteCheckedTraces(vtkMySQLDatabase *iDatabaseConnector)
362 {
363  this->DeleteTracesTemplate< ContourMeshContainer >(iDatabaseConnector,
365 }
366 
367 //-------------------------------------------------------------------------
368 
369 //-------------------------------------------------------------------------
371 {
373 }
374 
375 //-------------------------------------------------------------------------
376 
377 //-------------------------------------------------------------------------
379  int iTraceID)
380 {
382  UpdateElementHighlightingWithGivenTraceID(iTraceID);
383 }
384 
385 //-------------------------------------------------------------------------
386 
387 //-------------------------------------------------------------------------
389 {
391  UpdateElementVisibilityWithGivenTraceID(iTraceID);
392 }
393 
394 //-------------------------------------------------------------------------
395 
396 //-------------------------------------------------------------------------
398  vtkMySQLDatabase *iDatabaseConnector,
399  std::list< unsigned int > iListTraceIDs)
400 {
401  this->GetTracesInfoFromDBAndModifyContainerForVisuTemplate< ContourContainer >(
402  this->m_ContourContainerInfoForVisu, iDatabaseConnector, iListTraceIDs);
403 }
404 
405 //-------------------------------------------------------------------------
406 
407 //-------------------------------------------------------------------------
409 {
410  this->SetColorCodingTemplate< ContourMeshContainer >(
411  this->m_ContourContainerInfoForVisu, IsChecked);
412 }
413 
414 //-------------------------------------------------------------------------
415 
416 //-------------------------------------------------------------------------
418 {
420  {
422  }
423 }
424 
425 //-------------------------------------------------------------------------
426 
427 //-------------------------------------------------------------------------
429 {
431  {
433  }
434 }
435 
436 //-------------------------------------------------------------------------
437 
438 //-------------------------------------------------------------------------
440 {
441  std::list< unsigned int > ListCheckedContours =
443  if ( !ListCheckedContours.empty() )
444  {
446  std::list< unsigned int >::iterator iter = ListCheckedContours.begin();
447 
448  while ( iter != ListCheckedContours.end() )
449  {
450  unsigned int TimepointContour =
452 
453  if ( TimepointContour !=
454  static_cast< unsigned int >( *this->m_CurrentTimePoint ) )
455  {
456  emit PrintMessage(
457  tr(
458  "To see only the contours from the current timepoint in the table, right click on the table and select 'Show only in the table the contours for the current timepoint' ") );
459 
460  QMessageBox msgBox;
461  msgBox.setText(
462  tr("Please select only contours from the current timepoint: %1 !!")
463  .arg(*this->m_CurrentTimePoint) );
464  msgBox.exec();
465 
466  return false;
467  }
468  ++iter;
469  }
471  }
472  return true;
473 }
474 //-------------------------------------------------------------------------
475 
476 //-------------------------------------------------------------------------
477 void
479 CleanTWAndContainerForGivenTimePoint(vtkMySQLDatabase *iDatabaseConnector,
480  const std::list<unsigned int>& iTimePoints)
481 {
482  this->RemoveTracesFromTWAndContainerForVisuForSpecificTPsTemplate<ContourContainer>(
483  iDatabaseConnector, this->m_ContourContainerInfoForVisu, iTimePoints);
484 }
485 //-------------------------------------------------------------------------