GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBTrackRow.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 #include "GoDBTrackRow.h"
36 #include "GoDBRecordSetHelper.h"
38 #include <iostream>
39 
40 #include "vtkSmartPointer.h"
41 
43 {
44  this->InitializeMap();
45 }
46 
47 //-------------------------------------------------------------------------
48 
49 //-------------------------------------------------------------------------
50 GoDBTrackRow::GoDBTrackRow(vtkMySQLDatabase *DatabaseConnector,
52  unsigned int ImgSessionID,
53  std::string TraceVisu) : GoDBTraceRow()
54 {
55  this->InitializeMap();
56  this->SetImgSessionID(ImgSessionID);
57  this->SetTheBoundingBox(DatabaseConnector, Min, Max);
58  this->SetField("Points", TraceVisu);
59 
60  cout << "Track ID found: " << this->DoesThisBoundingBoxTrackExist(DatabaseConnector) << endl;
61 
62  if ( this->DoesThisBoundingBoxTrackExist(DatabaseConnector) )
63  {
64  std::cout << "The bounding box already exists for this track" << std::endl;
65  }
66 }
67 
68 //-------------------------------------------------------------------------
69 
70 //-------------------------------------------------------------------------
71 GoDBTrackRow::GoDBTrackRow(unsigned int ImagingSessionID) :
72  GoDBTraceRow()
73 {
74  this->InitializeMap();
75  this->SetImgSessionID(ImagingSessionID);
76 }
77 
78 //-------------------------------------------------------------------------
79 
80 //-------------------------------------------------------------------------
81 GoDBTrackRow::GoDBTrackRow(unsigned int iExistingID,
82  vtkMySQLDatabase *iDatabaseConnector) : GoDBTraceRow()
83 {
84  this->InitializeMap();
85  this->SetValuesForSpecificID(iExistingID, iDatabaseConnector);
86 }
87 
88 //-------------------------------------------------------------------------
89 
90 //-------------------------------------------------------------------------
91 GoDBTrackRow::GoDBTrackRow(vtkMySQLDatabase *DatabaseConnector,
92  vtkPolyData *TraceVisu, GoDBCoordinateRow Min, GoDBCoordinateRow Max,
93  unsigned int ImgSessionID) : GoDBTraceRow()
94 {
95  this->InitializeMap();
96  this->SetImgSessionID(ImgSessionID);
97  this->SetTheDataFromTheVisu(DatabaseConnector, TraceVisu, Min, Max);
98 }
99 
100 //-------------------------------------------------------------------------
101 
102 //-------------------------------------------------------------------------
104 {
105  this->m_TableName = "track";
106  this->m_TableIDName = "trackID";
107  this->m_CollectionName = "lineage";
108  this->m_CollectionIDName = "lineageID";
109  this->m_MapRow[this->m_TableIDName] = std::string( "0" );//ConvertToString< int >(0);
110  this->m_MapRow["lineageID"] = std::string( "0" );//ConvertToString< int >(0);
111  this->m_MapRow["TrackFamilyID"] = std::string( "0" );//ConvertToString< int >(0);
112 }
113 
114 //-------------------------------------------------------------------------
115 
116 //-------------------------------------------------------------------------
118  vtkMySQLDatabase *DatabaseConnector)
119 {
120  std::vector< FieldWithValue > Conditions;
121  this->AddConditions("ImagingSessionID", Conditions);
122  this->AddConditions("CoordIDMax", Conditions);
123  this->AddConditions("CoordIDMin", Conditions);
124 
125  return FindOneID(DatabaseConnector, "track", "trackID", Conditions);
126 }
127 
128 //-------------------------------------------------------------------------
129 
130 //-------------------------------------------------------------------------
131 int GoDBTrackRow::SaveInDB(vtkMySQLDatabase *DatabaseConnector)
132 {
133  return this->SaveInDBTemplate< GoDBTrackRow >(DatabaseConnector, this);
134 }
135 
136 //-------------------------------------------------------------------------
137 
138 //-------------------------------------------------------------------------
139 void GoDBTrackRow::SetTheDataFromTheVisu(vtkMySQLDatabase *DatabaseConnector,
140  vtkPolyData *TrackVisu,
141  GoDBCoordinateRow iCoordMin,
142  GoDBCoordinateRow iCoordMax)
143 {
144  this->SetTheDataFromTheVisuTemplate< vtkPolyDataMySQLTrackWriter >(
145  DatabaseConnector, TrackVisu, iCoordMin, iCoordMax);
146 }
147 
148 //-------------------------------------------------------------------------
149 
150 //-------------------------------------------------------------------------
151 void GoDBTrackRow::SetThePointsFromPolydata(vtkPolyData *iTrackVisu)
152 {
153  std::string PointsString = "0"; //in case the track has no more meshes
154 
155  if ( iTrackVisu )
156  {
157  vtkSmartPointer< vtkPolyDataMySQLTrackWriter > convert =
158  vtkSmartPointer< vtkPolyDataMySQLTrackWriter >::New();
159  PointsString = convert->GetMySQLText(iTrackVisu);
160  }
161  this->SetField("Points", PointsString);
162 }
int DoesThisBoundingBoxTrackExist(vtkMySQLDatabase *DatabaseConnector)
abstract class to be inherited by Contour,Mesh,Track and GoDBLineageRow
Definition: GoDBTraceRow.h:50
std::string m_TableIDName
Definition: GoDBRow.h:225
manages a map with keys matching fields of the gofiguredatabase Coordinate table and values of the ma...
virtual void InitializeMap()
virtual pure. initialize all the values of the map
bool SetValuesForSpecificID(int ID, vtkMySQLDatabase *iDatabaseConnector)
std::string m_TableName
Definition: GoDBRow.h:224
int FindOneID(vtkMySQLDatabase *DatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value)
SELECT ColumnName FROM TableName WHERE field = value.
virtual int SaveInDB(vtkMySQLDatabase *DatabaseConnector)
save the row in the database if the TraceID is set to "0", update the existing traceRow if the TraceI...
std::string m_CollectionIDName
check in the database if the Coordinate Min adn Max already exists, if yes fill the map["CoordIDMin"]...
Definition: GoDBTraceRow.h:154
void SetImgSessionID(unsigned int iImgSessionID)
set the ImagingSessionID field to iImgSessionID
void SetField(const std::string &key, const T &value)
convert the value into a string and assign it to the key in the map
Definition: GoDBRow.h:73
StringMapType m_MapRow
Definition: GoDBRow.h:223
std::string m_CollectionName
Definition: GoDBTraceRow.h:155
void AddConditions(const std::string &iNameOfField, std::vector< FieldWithValue > &ioFieldWithValue)
add as an element of ioFieldWithValue the name and value of the map with the key iNameOfField ...
Definition: GoDBRow.cxx:263
void SetTheDataFromTheVisu(vtkMySQLDatabase *DatabaseConnector, vtkPolyData *TrackVisu, GoDBCoordinateRow iCoordMin, GoDBCoordinateRow iCoordMax)
void SetTheBoundingBox(vtkMySQLDatabase *iDatabaseConnector, GoDBCoordinateRow Min, GoDBCoordinateRow Max)
check in the database if the Coordinate Min and Max already exists, if yes fill the map["CoordIDMin"]...
void SetThePointsFromPolydata(vtkPolyData *iTrackVisu)
convert the iTrackVisu into a string and set the field 'points' of the map