1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
/*=========================================================================
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <iostream>
#include "vtksys/CommandLineArguments.hxx"
#include "vtksys/SystemTools.hxx"
#include "vtkXMLDataElement.h"
#include "vtkXMLUtilities.h"
#include "vtkVVFileInstancePool.h"
#include "vtkVVFileInstance.h"
#include "vtkVVSnapshotPool.h"
#include "vtkVVSnapshot.h"
#include "vtkVVDataItemPool.h"
#include "vtkVVDataItemVolume.h"
#include "vtkVVLODDataItemVolumeHelper.h"
#include "XML/vtkXMLVVFileInstancePoolReader.h"
#include "XML/vtkXMLVVDataItemPoolReader.h"
#include "XML/vtkXMLVVSnapshotPoolReader.h"
int main(int argc, char *argv[])
{
// Parse the command line args
typedef vtksys::CommandLineArguments cmd_args_type;
cmd_args_type cmd_args;
cmd_args.Initialize(argc, argv);
// We need a session file
char *session_file = NULL;
cmd_args.AddArgument(
"--session", cmd_args_type::SPACE_ARGUMENT, &session_file, " ");
cmd_args.Parse();
// Seriously: we need that session file
if (!session_file)
{
std::cout << "[FAILED] Missing arg: --session file" << std::endl;
return EXIT_FAILURE;
}
if (!vtksys::SystemTools::FileExists(session_file))
{
std::cout << "[FAILED] Can not find: " << session_file << std::endl;
return EXIT_FAILURE;
}
// First read the XML session file
vtkXMLDataElement *xml = vtkXMLUtilities::ReadElementFromFile(session_file);
if (!xml)
{
std::cout << "[FAILED] Can not parse: " << session_file << std::endl;
return EXIT_FAILURE;
}
// Let's dig inside to find the file instance pool
// using FindNestedElementWithName and parse the contents with an XML reader
// This will give us the list of files loaded at the time the session
// was saved.
int res = EXIT_SUCCESS;
vtkVVFileInstancePool *fip = NULL;
vtkXMLObjectReader *fip_xmlr = NULL;
vtkXMLDataElement *fip_xml = NULL;
int fi_idx, f_idx;
fip = vtkVVFileInstancePool::New();
fip_xmlr = fip->GetNewXMLReader();
fip_xml = xml->LookupElementWithName(fip_xmlr->GetRootElementName());
if (!fip_xml)
{
std::cout << "[FAILED] Can not find XML element: "
<< fip_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
if (!fip_xmlr->Parse(fip_xml))
{
std::cout << "[FAILED] Can not parse XML element: "
<< fip_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
for (fi_idx = 0; fi_idx < fip->GetNumberOfFileInstances(); fi_idx++)
{
vtkVVFileInstance *fi = fip->GetNthFileInstance(fi_idx);
if (fi)
{
std::cout << "File instance #" << fi_idx << std::endl;
for (f_idx = 0; f_idx < fi->GetNumberOfFileNames(); f_idx++)
{
const char *fn = fi->GetNthFileName(f_idx);
if (fn)
{
std::cout << " - Filename #" << f_idx << ": " << fn << std::endl;
}
}
}
}
}
}
// Let's dig inside to find the snapshot pool and parse the contents
// with an XML reader as well.
// This will give us the list of files that *could* be loaded if the user
// selected a specific snapshot from the session file.
vtkVVSnapshotPool *sp = vtkVVSnapshotPool::New();
vtkXMLObjectReader *sp_xmlr = sp->GetNewXMLReader();
vtkXMLDataElement *sp_xml = xml->LookupElementWithName(
sp_xmlr->GetRootElementName());
if (sp_xml)
{
if (!sp_xmlr->Parse(sp_xml))
{
std::cout << "[FAILED] Can not parse Snapshot Pool XML element: "
<< sp_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
int s_idx;
for (s_idx = 0; s_idx < sp->GetNumberOfSnapshots(); s_idx++)
{
vtkVVSnapshot *s = sp->GetNthSnapshot(s_idx);
if (s)
{
std::cout << "-------------------------------------------------------------" << endl;
std::cout << "Snapshot #" << s_idx << " (" <<
s->GetDescription() << ")" << std::endl;
// Now parse the file instance pool inside each snapshot the same way
fip_xml = s->GetSerializedForm()->LookupElementWithName(
fip_xmlr->GetRootElementName());
if (fip_xml)
{
if (!fip_xmlr->Parse(fip_xml))
{
std::cout << "[FAILED] Can not parse XML element: "
<< fip_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
for (fi_idx = 0;fi_idx < fip->GetNumberOfFileInstances();fi_idx++)
{
vtkVVFileInstance *fi = fip->GetNthFileInstance(fi_idx);
if (fi)
{
std::cout << "File instance #" << fi_idx << std::endl;
for (f_idx = 0; f_idx < fi->GetNumberOfFileNames(); f_idx++)
{
const char *fn = fi->GetNthFileName(f_idx);
if (fn)
{
std::cout << " - Filename #"
<< f_idx << ": " << fn << std::endl;
}
}
}
}
}
}
}
}
}
}
fip->Delete();
fip_xmlr->Delete();
// Let's dig inside to find the data item pool
// using FindNestedElementWithName and parse the contents with an XML reader
// This will give us the list of data item loaded at the time the session
// was saved.
vtkVVDataItemPool *dip = NULL;
vtkXMLObjectReader *dip_xmlr = NULL;
vtkXMLDataElement *dip_xml = NULL;
int di_idx;
dip = vtkVVDataItemPool::New();
dip_xmlr = dip->GetNewXMLReader();
dip_xml = xml->LookupElementWithName(dip_xmlr->GetRootElementName());
if (!dip_xml)
{
std::cout << "[FAILED] Can not find XML element: "
<< dip_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
if (!dip_xmlr->Parse(dip_xml))
{
std::cout << "[FAILED] Can not parse XML element: "
<< dip_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
for (di_idx = 0; di_idx < dip->GetNumberOfDataItems(); di_idx++)
{
vtkVVDataItem *di = dip->GetNthDataItem(di_idx);
if (di)
{
std::cout << "Data item #" << di_idx << std::endl;
vtkVVDataItemVolume *div = vtkVVDataItemVolume::SafeDownCast(di);
if (div && div->GetLODHelper())
{
std::cout << " LOD Compression Ratio: " << div->GetLODHelper()->GetCompressionRatio() << std::endl;
}
}
}
}
}
// Let's dig inside to find the snapshot pool and parse the contents
// with an XML reader as well.
// This will give us the list of data items that *could* be loaded if the
// user selected a specific snapshot from the session file.
int s_idx;
for (s_idx = 0; s_idx < sp->GetNumberOfSnapshots(); s_idx++)
{
vtkVVSnapshot *s = sp->GetNthSnapshot(s_idx);
if (s)
{
std::cout << "-------------------------------------------------------------" << endl;
std::cout << "Snapshot #" << s_idx << " (" <<
s->GetDescription() << ")" << std::endl;
// Now parse the data item pool inside each data item the same way
dip_xml = s->GetSerializedForm()->LookupElementWithName(
dip_xmlr->GetRootElementName());
if (dip_xml)
{
if (!dip_xmlr->Parse(dip_xml))
{
std::cout << "[FAILED] Can not parse XML element: "
<< dip_xmlr->GetRootElementName() << std::endl;
res = EXIT_FAILURE;
}
else
{
for (di_idx = 0;di_idx < dip->GetNumberOfDataItems();di_idx++)
{
vtkVVDataItem *di = dip->GetNthDataItem(di_idx);
if (di)
{
std::cout << "Data item #" << di_idx << std::endl;
vtkVVDataItemVolume *div = vtkVVDataItemVolume::SafeDownCast(di);
if (div && div->GetLODHelper())
{
std::cout << " LOD Compression Ratio: " << div->GetLODHelper()->GetCompressionRatio() << std::endl;
}
}
}
}
}
}
}
dip->Delete();
dip_xmlr->Delete();
sp->Delete();
sp_xmlr->Delete();
// Bye
xml->Delete();
if (res == EXIT_SUCCESS)
{
std::cout << "[PASSED]" << std::endl;
}
return res;
}
|