35 #ifndef __GoDBImport_h
36 #define __GoDBImport_h
38 #include "vtkMySQLDatabase.h"
44 #include "QGoIOConfigure.h"
56 GoDBImport(std::string iServerName, std::string iLogin,
57 std::string iPassword,
int iImagingSessionID,
58 std::string iFilename,
int iCurrentTimePoint);
67 void ImportContours();
90 std::vector< int > GetVectorNewMeshIDs()
92 return this->m_NewMeshIDs;
97 std::vector< int > GetVectorNewContourIDs()
99 return this->m_NewContourIDs;
104 std::vector< int > GetVectorNewTracksIDs()
106 return this->m_NewTracksIDs;
114 return this->m_NewContourInfoForVisu;
135 std::string FindFieldName(std::string iLine);
139 std::string GetValueForTheLine(std::string iLine);
142 bool IsLineForNumberOfEntities(std::string iLine);
146 std::string SaveNoTracesEntities(
IntMapType & ioMapColorIDs,
151 void OpenDBConnection();
153 void CloseDBConnection();
159 void SaveTracesEntities(
const IntMapType & iMapColorIDs,
161 const std::string & iLineContent,
164 bool SaveIntensities =
false);
173 void SaveIntensityForMesh(std::string & ioLineContent,
182 template<
typename T >
183 std::string SaveImportedEntitiesInDatabase(
int iNumberOfEntities,
186 std::string LineContent;
191 for (
int i = 0; i < iNumberOfEntities; i++ )
194 LineContent = this->GetValuesFromInfile< T >(EntityToSave);
195 int OldID = atoi( EntityToSave.GetMapValue( EntityToSave.GetTableIDName() ).c_str() );
198 EntityToSave.SetField(EntityToSave.GetTableIDName(),
"0");
199 int NewID = EntityToSave.SaveInDB(this->m_DatabaseConnector);
200 ioMapMatchingIDs[OldID] = NewID;
208 template<
typename T >
209 std::string GetValuesFromInfile(T & ioEntityToFill)
211 std::string LineContent;
213 getline(this->m_InFile, LineContent);
214 std::string FieldName = this->FindFieldName(LineContent);
215 std::string ValueForField = this->GetValueForTheLine(LineContent);
216 while ( ValueForField !=
"NoValueOnTheLine" )
218 ioEntityToFill.SetField(FieldName, ValueForField);
219 getline(this->m_InFile, LineContent);
220 ValueForField = this->GetValueForTheLine(LineContent);
221 FieldName = this->FindFieldName(LineContent);
224 getline(this->m_InFile, LineContent);
231 template<
typename T >
233 std::string iFieldName, T & ioEntity)
235 typename IntMapType::const_iterator iter =
236 iMapIDs.find( atoi( ioEntity.GetMapValue(iFieldName).c_str() ) );
239 if ( iter == iMapIDs.end() )
243 int NewID = iter->second;
244 ioEntity.SetField(iFieldName, NewID);
251 template<
typename T >
252 void ReplaceCommonFieldsForTraces(T & ioEntityToSave,
257 ioEntityToSave.SetField(
258 "ImagingSessionID", this->m_ImagingSessionID);
259 this->ReplaceTheFieldWithNewIDs< T >(
260 iMapColorIDs,
"ColorID", ioEntityToSave);
261 this->ReplaceTheFieldWithNewIDs< T >(
262 iMapCoordIDs,
"CoordIDMax", ioEntityToSave);
263 this->ReplaceTheFieldWithNewIDs< T >(
264 iMapCoordIDs,
"CoordIDMin", ioEntityToSave);
265 if ( ioEntityToSave.GetCollectionIDName() !=
"NoneID" )
267 this->ReplaceTheFieldWithNewIDs< T >(
268 iMapCollectionIDs, ioEntityToSave.GetCollectionIDName(),
275 template<
typename T >
279 std::string & ioLineContent,
280 std::vector< int > & ioNewTracesIDs,
287 int NumberOfTraces = atoi( this->GetValueForTheLine(ioLineContent).c_str() );
289 getline(this->m_InFile, ioLineContent);
294 for (
int i = 0; i < NumberOfTraces; i++ )
296 ioLineContent = this->GetValuesFromInfile< T >(
299 if ( TraceToSave.GetTableName() ==
"mesh" )
301 if ( !iMapIDsSpecificOne.empty() )
303 this->ReplaceTheFieldWithNewIDs< T >(
304 iMapIDsSpecificOne,
"CellTypeID", TraceToSave);
306 if ( !iMapIDsSpecificTwo.empty() )
308 this->ReplaceTheFieldWithNewIDs< T >(
309 iMapIDsSpecificTwo,
"SubCellularID", TraceToSave);
312 this->ReplaceCommonFieldsForTraces(
313 TraceToSave, iMapColorIDs, iMapCoordIDs, iMapCollectionIDs);
314 int OldTraceID = atoi( TraceToSave.GetMapValue( TraceToSave.GetTableIDName() ).c_str() );
318 TraceToSave.SetField(TraceToSave.GetTableIDName(),
"0");
319 int NewTraceID = TraceToSave.DoesThisBoundingBoxExist(this->m_DatabaseConnector);
320 if ( NewTraceID == -1 )
322 NewTraceID = TraceToSave.SaveInDB(this->m_DatabaseConnector);
327 std::cout <<
"The trace" << OldTraceID <<
" has the same bounding box as ";
328 std::cout <<
"the existing trace " << NewTraceID;
329 std::cout <<
"so the imported contours belonging to the mesh " << OldTraceID;
330 std::cout <<
" will belong to the existing mesh " << NewTraceID << std::endl;
332 ioNewTracesIDs.push_back(NewTraceID);
333 ioMapTraceIDs[OldTraceID] = NewTraceID;