-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added reading and writing linear object collections to/from file.
- Loading branch information
1 parent
59db0c5
commit c338015
Showing
16 changed files
with
548 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/*=Auto========================================================================= | ||
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved. | ||
See COPYRIGHT.txt | ||
or http://www.slicer.org/copyright/copyright.txt for details. | ||
Program: 3D Slicer | ||
Module: $RCSfile: vtkMRMLTransformStorageNode.cxx,v $ | ||
Date: $Date: 2006/03/17 15:10:09 $ | ||
Version: $Revision: 1.2 $ | ||
=========================================================================auto=*/ | ||
|
||
#include "vtkMRMLLORLinearObjectCollectionStorageNode.h" | ||
#include "vtkMRMLLORLinearObjectCollectionNode.h" | ||
|
||
|
||
// Standard MRML Node Methods ------------------------------------------------------------ | ||
|
||
vtkMRMLLORLinearObjectCollectionStorageNode* vtkMRMLLORLinearObjectCollectionStorageNode | ||
::New() | ||
{ | ||
// First try to create the object from the vtkObjectFactory | ||
vtkObject* ret = vtkObjectFactory::CreateInstance( "vtkMRMLLORLinearObjectCollectionStorageNode" ); | ||
if( ret ) | ||
{ | ||
return ( vtkMRMLLORLinearObjectCollectionStorageNode* )ret; | ||
} | ||
// If the factory was unable to create the object, then create it here. | ||
return new vtkMRMLLORLinearObjectCollectionStorageNode(); | ||
} | ||
|
||
|
||
vtkMRMLNode* vtkMRMLLORLinearObjectCollectionStorageNode | ||
::CreateNodeInstance() | ||
{ | ||
// First try to create the object from the vtkObjectFactory | ||
vtkObject* ret = vtkObjectFactory::CreateInstance( "vtkMRMLLORLinearObjectCollectionStorageNode" ); | ||
if( ret ) | ||
{ | ||
return ( vtkMRMLLORLinearObjectCollectionStorageNode* )ret; | ||
} | ||
// If the factory was unable to create the object, then create it here. | ||
return new vtkMRMLLORLinearObjectCollectionStorageNode(); | ||
} | ||
|
||
|
||
|
||
void vtkMRMLLORLinearObjectCollectionStorageNode | ||
::PrintSelf(ostream& os, vtkIndent indent) | ||
{ | ||
this->Superclass::PrintSelf(os,indent); | ||
} | ||
|
||
|
||
// Constructors and Destructors -------------------------------------------------------------------- | ||
|
||
vtkMRMLLORLinearObjectCollectionStorageNode | ||
::vtkMRMLLORLinearObjectCollectionStorageNode() | ||
{ | ||
} | ||
|
||
|
||
vtkMRMLLORLinearObjectCollectionStorageNode | ||
::~vtkMRMLLORLinearObjectCollectionStorageNode() | ||
{ | ||
} | ||
|
||
// Storage node specific methods ---------------------------------------------------------------------------- | ||
bool vtkMRMLLORLinearObjectCollectionStorageNode | ||
::CanReadInReferenceNode(vtkMRMLNode *refNode) | ||
{ | ||
return refNode->IsA( "vtkMRMLLORLinearObjectCollectionNode" ); | ||
} | ||
|
||
|
||
void vtkMRMLLORLinearObjectCollectionStorageNode | ||
::InitializeSupportedWriteFileTypes() | ||
{ | ||
this->SupportedWriteFileTypes->InsertNextValue("Linear Object Collection (.xml)"); | ||
} | ||
|
||
|
||
const char* vtkMRMLLORLinearObjectCollectionStorageNode | ||
::GetDefaultWriteFileExtension() | ||
{ | ||
return "xml"; | ||
} | ||
|
||
|
||
|
||
// Read and Write methods ---------------------------------------------------------------------------- | ||
int vtkMRMLLORLinearObjectCollectionStorageNode | ||
::ReadDataInternal(vtkMRMLNode *refNode) | ||
{ | ||
vtkMRMLLORLinearObjectCollectionNode* collectionNode = vtkMRMLLORLinearObjectCollectionNode::SafeDownCast( refNode ); | ||
|
||
std::string fullName = this->GetFullNameFromFileName(); | ||
if ( fullName == std::string( "" ) ) | ||
{ | ||
vtkErrorMacro("vtkMRMLLORLinearObjectCollectionNode: File name not specified"); | ||
return 0; | ||
} | ||
|
||
// Clear the current buffer prior to importing | ||
collectionNode->Clear(); | ||
|
||
vtkXMLDataParser* parser = vtkXMLDataParser::New(); | ||
parser->SetFileName( fullName.c_str() ); | ||
parser->Parse(); | ||
|
||
collectionNode->FromXMLElement( parser->GetRootElement() ); | ||
|
||
// The buffer name should already be specified | ||
// The scene should already be populated with the desired transforms | ||
|
||
parser->Delete(); | ||
|
||
return 1; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
int vtkMRMLLORLinearObjectCollectionStorageNode | ||
::WriteDataInternal(vtkMRMLNode *refNode) | ||
{ | ||
vtkMRMLLORLinearObjectCollectionNode* collectionNode = vtkMRMLLORLinearObjectCollectionNode::SafeDownCast( refNode ); | ||
|
||
std::string fullName = this->GetFullNameFromFileName(); | ||
if ( fullName == std::string( "" ) ) | ||
{ | ||
vtkErrorMacro("vtkMRMLLORLinearObjectCollectionNode: File name not specified"); | ||
return 0; | ||
} | ||
|
||
std::ofstream output( fullName.c_str() ); | ||
|
||
if ( ! output.is_open() ) | ||
{ | ||
vtkErrorMacro( "Record file could not be opened!" ); | ||
return 0; | ||
} | ||
|
||
output << collectionNode->ToXMLString(); | ||
|
||
output.close(); | ||
|
||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*=auto========================================================================= | ||
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved. | ||
See COPYRIGHT.txt | ||
or http://www.slicer.org/copyright/copyright.txt for details. | ||
Program: 3D Slicer | ||
Module: $RCSfile: vtkMRMLLORLinearObjectCollectionStorageNode.h,v $ | ||
Date: $Date: 2006/03/19 17:12:29 $ | ||
Version: $Revision: 1.3 $ | ||
=========================================================================auto=*/ | ||
|
||
#ifndef __vtkMRMLLORLinearObjectCollectionStorageNode_h | ||
#define __vtkMRMLLORLinearObjectCollectionStorageNode_h | ||
|
||
// Standard includes | ||
#include <ctime> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <utility> | ||
#include <vector> | ||
|
||
//VTK includes | ||
#include "vtkMRMLStorageNode.h" | ||
#include "vtkStringArray.h" | ||
|
||
// TransformRecorder includes | ||
#include "vtkSlicerLinearObjectRegistrationModuleMRMLExport.h" | ||
|
||
|
||
/// Storage nodes has methods to read/write transform bufferss to/from disk. | ||
class VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_MRML_EXPORT | ||
vtkMRMLLORLinearObjectCollectionStorageNode : public vtkMRMLStorageNode | ||
{ | ||
public: | ||
vtkTypeMacro( vtkMRMLLORLinearObjectCollectionStorageNode, vtkMRMLStorageNode ); | ||
|
||
// Standard MRML node methods | ||
static vtkMRMLLORLinearObjectCollectionStorageNode* New(); | ||
virtual vtkMRMLNode* CreateNodeInstance(); | ||
virtual const char* GetNodeTagName() { return "LORLinearObjectCollectionStorage"; }; | ||
void PrintSelf(ostream& os, vtkIndent indent); | ||
// No need for special read/write/copy | ||
|
||
// Initialize all the supported write file types | ||
virtual void InitializeSupportedWriteFileTypes(); | ||
// Return a default file extension for writing | ||
virtual const char* GetDefaultWriteFileExtension(); | ||
|
||
/// Support only linear object registration nodes | ||
virtual bool CanReadInReferenceNode(vtkMRMLNode* refNode); | ||
|
||
protected: | ||
// Constructor/deconstructor | ||
vtkMRMLLORLinearObjectCollectionStorageNode(); | ||
~vtkMRMLLORLinearObjectCollectionStorageNode(); | ||
vtkMRMLLORLinearObjectCollectionStorageNode(const vtkMRMLLORLinearObjectCollectionStorageNode&); | ||
void operator=(const vtkMRMLLORLinearObjectCollectionStorageNode&); | ||
|
||
|
||
/// Read data and set it in the referenced node | ||
virtual int ReadDataInternal(vtkMRMLNode *refNode); | ||
|
||
/// Write data from a referenced node | ||
virtual int WriteDataInternal(vtkMRMLNode *refNode); | ||
|
||
}; | ||
|
||
#endif |
Oops, something went wrong.