GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBCollectionOfTraces.h
Go to the documentation of this file.
1 
2 /*=========================================================================
3  Authors: The GoFigure Dev. Team.
4  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
5 
6  Copyright (c) 2009-11, President and Fellows of Harvard College.
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions are met:
11 
12  Redistributions of source code must retain the above copyright notice,
13  this list of conditions and the following disclaimer.
14  Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17  Neither the name of the President and Fellows of Harvard College
18  nor the names of its contributors may be used to endorse or promote
19  products derived from this software without specific prior written
20  permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
26  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 =========================================================================*/
35 #ifndef __GoDBCollectionOfTraces_h
36 #define __GoDBCollectionOfTraces_h
37 
38 #include "MegaVTK2Configure.h"
39 #include "GoDBRecordSetHelper.h"
40 #include "vtkMySQLDatabase.h"
41 #include "GoDBRow.h"
42 #include "GoDBCoordinateRow.h"
45 #include <map>
46 #include <QColor>
47 
54 class QGOIO_EXPORT GoDBCollectionOfTraces
55 {
56 public:
57 
59  //refactoring
61  std::string CollectionName, std::string Traces,
62  std::string iCollectionOfName, unsigned int iImgSessionID);
63  virtual ~GoDBCollectionOfTraces();
64 
66  typedef std::pair< std::string, QColor > NameWithColorData;
67 
74  void SetCollectionInfo(std::string iCollectionName,
75  std::string iTracesName,
76  std::string iCollectionOfName);
77 
81  void SetImgSessionID(unsigned int iImgSessionID);
82 
83  //Modif into Database
89  void DeleteTraceInDB(int TraceToDelete, vtkMySQLDatabase *DatabaseConnector);
90 
91  //Modif into Database
98  void DeleteTracesInDB(std::list< unsigned int > TracesToDelete,
99  vtkMySQLDatabase *DatabaseConnector);
100 
101  //Modif into Database
110  void UpdateCollectionIDOfSelectedTraces(
111  std::list< unsigned int > iListSelectedTraces, unsigned int iCollectionID,
112  vtkMySQLDatabase *iDatabaseConnector);
113 
119  std::string GetCollectionOf();
120 
121  //******************************Modif-Refactoring************************************************
122  //public:
123  //Modif into Database
130  void RecalculateDBBoundingBox(
131  vtkMySQLDatabase *iDatabaseConnector, int iCollectionID);
132 
139  void RecalculateDBBoundingBox(
140  vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTracesIDs);
141 
147  std::list< NameWithColorData > GetAllTracesIDsWithColor(
148  vtkMySQLDatabase *iDatabaseConnector);
149 
156  std::list< NameWithColorData > GetTracesIDsWithColorForATimePoint(
157  vtkMySQLDatabase *iDatabaseConnector, unsigned int iTimePoint);
158 
168  template< typename T >
169  int CreateCollectionWithNoTracesNoPoints(vtkMySQLDatabase *iDatabaseConnector,
170  NameWithColorData iColor,
171  T iNewCollection, int iTimePoint = -1)
172  {
173  iNewCollection.SetField("ImagingSessionID", this->m_ImgSessionID);
174 
175  int CoordIDMax = GetCoordIDMaxForBoundingBoxWithNoTraces(iDatabaseConnector);
176  int CoordIDMin = GetCoordIDMinForBoundingBoxWithNoTraces(iDatabaseConnector);
177 
178  if ( iTimePoint != -1 )
179  {
180  this->SetTheTimePointCoordinatesForMesh(
181  iTimePoint, CoordIDMax, CoordIDMin, iDatabaseConnector);
182  }
183  std::string CollectionID = iNewCollection.GetMapValue(this->m_CollectionIDName);
184  if ( CollectionID != "0" )
185  {
186  if (CollectionID == "noValue") //case for lineage
187  {
188  return this->CreateNewTraceInDB< T >( iNewCollection, iDatabaseConnector,
189  CoordIDMin, CoordIDMax, iColor);
190  }
191  else
192  {
193  return this->CreateNewTraceInDB< T >( iNewCollection, iDatabaseConnector,
194  CoordIDMin, CoordIDMax, iColor,
195  ss_atoi< unsigned int >(CollectionID) );
196  }
197  }
198  else
199  {
200  return this->CreateNewTraceInDB< T >(iNewCollection, iDatabaseConnector,
201  CoordIDMin, CoordIDMax, iColor, 0);
202  }
203  }
204 
215  template< typename T >
216  unsigned int CreateNewTraceInDB(T iTrace, vtkMySQLDatabase *iDatabaseConnector,
217  NameWithColorData iColor, unsigned int iCollectionID)
218  {
219  iTrace.SetColor(iColor.second.red(), iColor.second.green(),
220  iColor.second.blue(), iColor.second.alpha(), iColor.first,
221  iDatabaseConnector);
222 
223  iTrace.SetCollectionID(iCollectionID);
224  return iTrace.SaveInDB(iDatabaseConnector);
225  }
226 
230  template< typename T >
231  unsigned int CreateNewTraceInDB(T iTrace, vtkMySQLDatabase *iDatabaseConnector,
232  unsigned int iCoordIDMin, unsigned int iCoordIDMax, NameWithColorData iColor,
233  unsigned int iCollectionID)
234  {
235  iTrace.SetField( "CoordIDMin", ConvertToString< unsigned int >(iCoordIDMin) );
236  iTrace.SetField( "CoordIDMax", ConvertToString< unsigned int >(iCoordIDMax) );
237  iTrace.SetColor(iColor.second.red(), iColor.second.green(),
238  iColor.second.blue(), iColor.second.alpha(), iColor.first,
239  iDatabaseConnector);
240 
241  iTrace.SetCollectionID(iCollectionID);
242  return iTrace.SaveInDB(iDatabaseConnector);
243  }
244 
248  template< typename T > //for lineage
249  unsigned int CreateNewTraceInDB(T iTrace, vtkMySQLDatabase *iDatabaseConnector,
250  unsigned int iCoordIDMin, unsigned int iCoordIDMax,
251  NameWithColorData iColor)
252  {
253  iTrace.SetField( "CoordIDMin", ConvertToString< unsigned int >(iCoordIDMin) );
254  iTrace.SetField( "CoordIDMax", ConvertToString< unsigned int >(iCoordIDMax) );
255  iTrace.SetColor(iColor.second.red(), iColor.second.green(),
256  iColor.second.blue(), iColor.second.alpha(), iColor.first,
257  iDatabaseConnector);
258  return iTrace.SaveInDB(iDatabaseConnector);
259  }
260 
268  template< typename T >
269  void ChangeColorForTrace(unsigned int iTraceID,
270  NameWithColorData iNewColor, vtkMySQLDatabase *iDatabaseConnector)
271  {
272  T tempTrace;
273 
274  tempTrace.SetValuesForSpecificID(iTraceID, iDatabaseConnector);
275  tempTrace.SetColor(iNewColor.second.red(), iNewColor.second.green(),
276  iNewColor.second.blue(), iNewColor.second.alpha(),
277  iNewColor.first, iDatabaseConnector);
278  tempTrace.SaveInDB(iDatabaseConnector);
279  }
280 
287  std::list< unsigned int > GetListTracesIDsFromThisCollectionOf(
288  vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTraces);
289 
298  std::list< unsigned int > GetListCollectionIDs(
299  vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTracesIDs,
300  bool ExcludeZero = true, bool Distinct = true);
301 
308  std::list< unsigned int > GetListTracesIDWithNoPoints(
309  std::list< unsigned int > iListTracesIDs, vtkMySQLDatabase *iDatabaseConnector);
310 
317  std::list< unsigned int > GetLastCreatedTracesIDs(
318  vtkMySQLDatabase *iDatabaseConnector, int iNumberOfTraces);
319 
329  void UpdateValueForListTraces(
330  vtkMySQLDatabase *iDatabaseConnector,std::string iNameValue,
331  std::string iValue, std::list<unsigned int> iListTraceIDs);
332 
341  std::list<double*> GetCoordinateCenterBoundingBox(vtkMySQLDatabase *iDatabaseConnector,
342  unsigned int iTraceID);
343 
352  std::list<unsigned int> GetTraceIDsWithTimePointAndCollectionID(vtkMySQLDatabase *iDatabaseConnector,
353  unsigned int iCollectionID,unsigned int iTimePoint);
354 
362  std::list<unsigned int> GetTimePointWithSeveralTracesFromTheList(
363  vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTraceIDs);
364 
373  int GetMaxTraceIDsForSpecificTimePoint(vtkMySQLDatabase *iDatabaseConnector,
374  std::list<unsigned int> iListTraceIDs,unsigned int iTimePoint);
375 
384  std::list<unsigned int> GetNonMaxTraceIDsForSpecificTimePoint(
385  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListTraceIDs,
386  unsigned int iTimePoint,unsigned int iMaxTraceID);
387 
395  std::list<unsigned int> GetListTimePointsFromTraceIDs(
396  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListTraceIDs);
397 
406  std::list<unsigned int> GetTraceIDsBelongingToCollectionID(
407  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListTraceIDs,
408  unsigned int iCollectionID);
409 
416  std::list<unsigned int> GetTraceIDsBelongingToCollectionID(
417  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListCollectionIDs);
418 
419  std::list<unsigned int> GetTraceIDsBelongingToListTimePoints(
420  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListTPs);
421 
428  std::list<unsigned int> GetTimePointsForTraceIDs(
429  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListTraceIDs);
430 
439  std::list<unsigned int> GetTraceIDsWithTimePointInf(
440  vtkMySQLDatabase *iDatabaseConnector,std::list<unsigned int> iListTraceIDs,
441  unsigned int iTimePoint);
442 
451  unsigned int GetBoundedBoxTimePoint(
452  vtkMySQLDatabase *iDatabaseConnector, unsigned int iTraceID, bool MinTimePoint = true);
453 
462  template<typename T>
464  vtkMySQLDatabase* iDatabaseConnector, unsigned int iImgSessionID,
465  std::list<unsigned int> iListTraces)
466 {
467  std::list<T> oListTracesResults;
468  std::vector<std::string> TraceAttributes = this->GetAttributesForTraces();
469  FieldWithValue CoordinateCondition = {"CoordIDMin", "CoordID", "="};
470  FieldWithValue ColorCondition = {"ColorID", "ColorID", "="};
471 
472  GetInfoFromDBAndModifyListStructure<T>(
473  oListTracesResults, iDatabaseConnector,
474  TraceAttributes, this->m_TracesName, "coordinate", "color",
475  CoordinateCondition, ColorCondition, "ImagingSessionID",
476  iImgSessionID, this->m_TracesIDName, iListTraces);
477  return oListTracesResults;
478 }
483  int GetTraceIDWithLowestTimePoint(vtkMySQLDatabase *iDatabaseConnector,
484  std::list<unsigned int> iListTraceIDs);
485 
486  std::list<unsigned int> GetTrackFamilyDataFromDB(
487  vtkMySQLDatabase *iDatabaseConnector);
488 
489  std::list<unsigned int> GetTrackFamiliesForLineages(
490  vtkMySQLDatabase *iDatabaseConnector, std::list<unsigned int> iLineagesID);
491 
496  std::list<unsigned int> GetTrackFamilyID(vtkMySQLDatabase *iDatabaseConnector,
497  std::list<unsigned int> iListTrackIDs);
498 
499  std::string GetPoints(vtkMySQLDatabase *iDatabaseConnector,
500  std::string iTraceName,
501  unsigned int iTraceID);
502 
503  std::vector<unsigned int> GetTrackFamily(vtkMySQLDatabase *iDatabaseConnector,
504  unsigned int iTrackID);
505 
506  bool isMother(vtkMySQLDatabase *iDatabaseConnector, unsigned int iTrackID);
507 
508 protected:
509 
510  std::string m_CollectionName;
511  std::string m_CollectionIDName;
512  std::string m_TracesName;
513  std::string m_TracesIDName;
514  std::string m_CollectionOfName;
515  std::string m_CollectionOfIDName;
516  unsigned int m_ImgSessionID;
517 
520  int CreateNewCollection();
521 
525  int CreateNewCollection(vtkMySQLDatabase *DatabaseConnector, GoDBTraceRow & myNewObject);
526 
528  void UpdateBoundingBoxInDB(int iCoordIDMin, int iCoordIDMax,
529  int iTraceID, vtkMySQLDatabase *iDatabaseConnector);
530 
531  //Modif into Database
533  void UpdateCollectionIDOfSelectedTrace(int iSelectedTraceID, int inewCollectionID,
534  vtkMySQLDatabase *DatabaseConnector);
535 
536  //******************************Modif-Refactoring************************************************
537  //protected:
538 
539  // get from Database and/or Modif into Database
550  void SetTheTimePointCoordinatesForMesh(unsigned int iTimePoint,
551  int & ioCoordIDMax,
552  int & ioCoordIDMin,
553  vtkMySQLDatabase *iDatabaseConnector);
554 
560  int GetCoordIDMaxForBoundingBoxWithNoTraces(
561  vtkMySQLDatabase *iDatabaseConnector);
562 
568  int GetCoordIDMinForBoundingBoxWithNoTraces(
569  vtkMySQLDatabase *iDatabaseConnector);
570 
571  // get from Database and/or Modif into Database
574  int GetCoordMinID(vtkMySQLDatabase *DatabaseConnector, int iTraceID);
575 
576  //get from Database and/or Modif into Database
579  int GetCoordMaxID(vtkMySQLDatabase *DatabaseConnector, int iTraceID);
580 
583  GoDBCoordinateRow GetCollectionOfTracesCoordMax(
584  vtkMySQLDatabase *DatabaseConnector, std::list< unsigned int > iListCollectionOfTracesID);
585 
588  GoDBCoordinateRow GetCollectionOfTracesCoordMin(
589  vtkMySQLDatabase *DatabaseConnector, std::list< unsigned int > iListCollectionOfTracesID);
590 
598  void GetFieldsNeededForQueryForColorData(
599  std::vector< std::string > & ioSelectedFields,
600  std::vector< std::string > & ioJoinTablesOnTraceTable);
601 
608  std::list< NameWithColorData >
609  GetListNameWithColorDataFromResultsQuery(
610  std::vector< std::vector< std::string > > iResultsQuery);
611 
612  std::vector<std::string> GetAttributesForTraces();
613 
614 };
615 #endif
GoDBTableWidgetContainer::TWContainerType TWContainerType
void ChangeColorForTrace(unsigned int iTraceID, NameWithColorData iNewColor, vtkMySQLDatabase *iDatabaseConnector)
update the color of the specified trace with iNewColor in the database
abstract class to be inherited by Contour,Mesh,Track and GoDBLineageRow
Definition: GoDBTraceRow.h:50
int CreateCollectionWithNoTracesNoPoints(vtkMySQLDatabase *iDatabaseConnector, NameWithColorData iColor, T iNewCollection, int iTimePoint=-1)
save the collection in the database after getting an empty bounding box and return the corresponding ...
manages a map with keys matching fields of the gofiguredatabase Coordinate table and values of the ma...
std::vector< std::pair< GoDBTraceInfoForTableWidget, std::vector< std::string > > > TWContainerType
unsigned int CreateNewTraceInDB(T iTrace, vtkMySQLDatabase *iDatabaseConnector, unsigned int iCoordIDMin, unsigned int iCoordIDMax, NameWithColorData iColor, unsigned int iCollectionID)
std::pair< std::string, QColor > NameWithColorData
std::list< T > GetListStructureFromDB(vtkMySQLDatabase *iDatabaseConnector, unsigned int iImgSessionID, std::list< unsigned int > iListTraces)
get a list of structures filled with data from the database
unsigned int CreateNewTraceInDB(T iTrace, vtkMySQLDatabase *iDatabaseConnector, unsigned int iCoordIDMin, unsigned int iCoordIDMax, NameWithColorData iColor)
unsigned int CreateNewTraceInDB(T iTrace, vtkMySQLDatabase *iDatabaseConnector, NameWithColorData iColor, unsigned int iCollectionID)
set the bounding box, the color and the collectionID of the trace,save it in the database and return ...
this class handles the interaction between the database and the children of QGoDBTraceManager ...