Text archives Help
- From: brownlee@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r2252 - in trunk: Core/Util Model/Readers scenes/csafe/python scenes/csafe/src
- Date: Tue, 6 May 2008 02:08:21 -0600 (MDT)
Author: brownlee
Date: Tue May 6 02:08:20 2008
New Revision: 2252
Modified:
trunk/Core/Util/Endian.h
trunk/Model/Readers/UDAReader.cc
trunk/Model/Readers/UDAReader.h
trunk/scenes/csafe/python/Configuration.py
trunk/scenes/csafe/python/Histogram.py
trunk/scenes/csafe/python/SceneInfo.py
trunk/scenes/csafe/python/csafe_demo.py
trunk/scenes/csafe/src/CDTest.h
Log:
sci notation, fixed endian issue for UDAReader
Modified: trunk/Core/Util/Endian.h
==============================================================================
--- trunk/Core/Util/Endian.h (original)
+++ trunk/Core/Util/Endian.h Tue May 6 02:08:20 2008
@@ -29,6 +29,7 @@
#ifndef Manta_Endian_h
#define Manta_Endian_h
+#include <Core/Geometry/VectorT.h>
#include <MantaTypes.h>
#include <Core/Color/ColorSpace.h>
Modified: trunk/Model/Readers/UDAReader.cc
==============================================================================
--- trunk/Model/Readers/UDAReader.cc (original)
+++ trunk/Model/Readers/UDAReader.cc Tue May 6 02:08:20 2008
@@ -1,6 +1,7 @@
#include <Model/Readers/UDAReader.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
+#include <Core/Util/Endian.h>
#include <iostream>
#include <fstream>
#include <cassert>
@@ -32,6 +33,69 @@
return st;
}
+void UDAReader::readUDAHeader(string directory)
+{
+ string filename;
+ assert(directory.length());
+ if (directory[directory.length()-1] != '/')
+ directory = directory + string("/");
+ _directory = directory;
+ filename = directory + string("index.xml");
+ cout << "UDAReader, reading header from: " << filename << endl;
+ xmlDocPtr doc;
+ xmlNodePtr cur;
+ doc = xmlParseFile(filename.c_str());
+ if (doc == NULL ) {
+ cerr << "Document not parsed successfully. \n";
+ return;
+ }
+ cur = xmlDocGetRootElement(doc);
+ if (cur == NULL) {
+ fprintf(stderr,"empty document\n");
+ xmlFreeDoc(doc);
+ return;
+ }
+ if (xmlStrcmp(cur->name, (const xmlChar *) "Uintah_DataArchive")) {
+ cerr << "document of the wrong type, root node !=
Uintah_specification";
+ xmlFreeDoc(doc);
+ return;
+ }
+ cur = cur->xmlChildrenNode;
+ while (cur != NULL)
+ {
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"variables")))
+ {
+ xmlNodePtr t = cur->xmlChildrenNode;
+ while (t != NULL)
+ {
+ if ((!xmlStrcmp(t->name, (const xmlChar*)"variable")))
+ {
+ string name = string((const char*)xmlGetProp(t,(const
xmlChar*)"name"));
+ string type = string((const
char*)xmlGetProp(t,(const xmlChar*)"type"));
+ if (type.find("float") != string::npos &&
type.find("CCVariable") != string::npos)
+ _varHeaders[name] = VarHeader(name, "CCVariable",
"float");
+ }
+ t = t->next;
+ }
+ }
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"timesteps")))
+ {
+ xmlNodePtr t = cur->xmlChildrenNode;
+ while (t != NULL)
+ {
+ if ((!xmlStrcmp(t->name, (const xmlChar*)"timestep")))
+ {
+ //TODO: track timesteps
+ }
+ t = t->next;
+ }
+ }
+ cur = cur->next;
+ }
+ xmlFreeDoc(doc);
+ cout << "UDAReader complete\n";
+}
+
void UDAReader::readUDA(string directory, string volumeVarName)
{
_volumeVarName = volumeVarName;
@@ -62,7 +126,20 @@
}
cur = cur->xmlChildrenNode;
while (cur != NULL)
- {
+ {
+
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"Meta")))
+ {
+ xmlNodePtr t = cur->xmlChildrenNode;
+ while (t != NULL)
+ {
+ if ((!xmlStrcmp(t->name, (const xmlChar*)"endianness")))
+ {
+ _endianness = string((const
char*)xmlNodeListGetString(doc, t->xmlChildrenNode, 1));
+ }
+ t = t->next;
+ }
+ }
if ((!xmlStrcmp(cur->name, (const xmlChar *)"timesteps")))
{
xmlNodePtr t = cur->xmlChildrenNode;
@@ -127,7 +204,9 @@
{
if ((!xmlStrcmp(t->name, (const xmlChar*)"Datafile")))
{
- parseDataFile(string(timestep.dir + string((const
char*)xmlGetProp(t,(const xmlChar*)"href"))), timestep);
+ string file = string(timestep.dir + string((const
char*)xmlGetProp(t,(const xmlChar*)"href")));
+ if (file.find("l0") != string::npos)
+ parseDataFile(file, timestep);
}
t = t->next;
}
@@ -286,7 +365,7 @@
//cerr << "need to compress data\n";
int nByteMode = sizeof(float); //TODO: unhardcode!
string data;
- int datasize = var.end-var.start;
+ int datasize = var.end-var.start+1;
//string bufferStr;
string* uncompressedData = &data;
//FILE* ip;
@@ -309,7 +388,7 @@
}
- //data.resize(datasize);
+ data.resize(datasize);
#ifdef _WIN32
// casting from const char* -- use caution
@@ -326,7 +405,17 @@
//ic.cur += datasize;
bool use_gzip = true;
- bool swapBytes = true;
+ bool swapBytes = false;
+ if (_endianness == "")
+ {
+ cerr << "warning: endianness of file not specified, guessing big
endian\n";
+ _endianness = "big_endian";
+ }
+ string machine = "little_endian";
+ if (is_big_endian())
+ machine = "big_endian";
+ if (machine != _endianness)
+ swapBytes = true;
if (use_gzip) {
// use gzip compression
@@ -370,20 +459,17 @@
char* bufferP = buffer;
float* sphereDataPtr = t.sphereData;
- if (var.type == particleVariable)
+ if (var.type == particleVariable && var.dataType ==pointT)
{
- for (int i = 0; i < var.numParticles; i++)
- {
- if (var.dataType == pointT)
- {
- Vector pos = readPoint(bufferP);
+ for (int i = 0; i < var.numParticles; i++)
+ {
+ Vector pos = readPoint(bufferP);
bufferP += sizeof(double)*3;
sphereDataPtr[0] = pos[0];
sphereDataPtr[1] = pos[1];
sphereDataPtr[2] = pos[2];
- }
sphereDataPtr += t.numSphereVars;
- }
+ }
}
else if (var.name == _volumeVarName)
{
@@ -395,19 +481,18 @@
"\nh: " << h[0] << " " << h[1] << " " << h[2] << endl;
cout << "data size: " << bufferStr.length()/4 << endl;
int l0 = int(l[0]), l1 = int(l[1]), l2 = int(l[2]), h0 = int(h[0]),
h1 = int(h[1]), h2 = int(h[2]);
- for( int x = l0; x < h0; x++)
+ for( int x = l0; x <= h0; x++)
{
- for(int y = l1; y < h1; y++)
+ for(int y = l1; y <= h1; y++)
{
- for(int z = l2; z < h2; z++)
+ for(int z = l2; z <= h2; z++)
{
float value = 0;
if (var.dataType == floatT)
{
- value = readFloat(bufferP);
- bufferP += sizeof(float);
+ value = readFloat(bufferP);
+ bufferP += sizeof(float);
}
-
(*(t.volume))(x,y,z) = value;
}
}
Modified: trunk/Model/Readers/UDAReader.h
==============================================================================
--- trunk/Model/Readers/UDAReader.h (original)
+++ trunk/Model/Readers/UDAReader.h Tue May 6 02:08:20 2008
@@ -51,19 +51,30 @@
float* sphereData;
int numSphereVars, numSpheres;
};
+ struct VarHeader //variable information, from the index.xml header
+ {
+ VarHeader() {}
+ VarHeader(std::string name_, std::string varType_, std::string
dataType_)
+ { name = name_; varType = varType_; dataType = dataType_; }
+ std::string name, varType, dataType;
+ };
UDAReader() {}
+ void readUDAHeader(std::string directory);
void readUDA(std::string directory, std::string volumeVarName);
void parseTimestepFile(std::string filename);
void parseDataFile(std::string file, Timestep& t);
std::vector<Timestep> timesteps;
+ int getNumVariables() { return _varHeaders.size(); }
+ VarHeader getVarHeader(int i) { int j = 0; for(std::map<std::string,
VarHeader>::iterator itr = _varHeaders.begin(); itr != _varHeaders.end();
itr++) { if (j++ == i) return itr->second; } return VarHeader(); }
private:
+ std::string _endianness;
std::string _volumeVarName;
std::string _directory;
void readData(std::string filename, Timestep& t);
Vector readPoint(char* p);
float readFloat(char* p);
-
+ std::map<std::string, VarHeader> _varHeaders;
};
}
Modified: trunk/scenes/csafe/python/Configuration.py
==============================================================================
--- trunk/scenes/csafe/python/Configuration.py (original)
+++ trunk/scenes/csafe/python/Configuration.py Tue May 6 02:08:20 2008
@@ -112,7 +112,7 @@
i+=1
transferFID = int(lines[i].strip())
histValues1 = []
- for i in range(100):
+ for i in range(scene.histogramBuckets):
histValues1.append(5.0)
histoGroup =
Histogram.HistogramGroup(scene.frame.panel, histValues1, cropColorMin,
cropColorMax, 300.0, 40.0, scene.frame.transferFunctions[transferFID],
scene.frame.tPanel, scene, index, name)
histoGroup.SetBackgroundColour(wx.Colour(90,90,90))
Modified: trunk/scenes/csafe/python/Histogram.py
==============================================================================
--- trunk/scenes/csafe/python/Histogram.py (original)
+++ trunk/scenes/csafe/python/Histogram.py Tue May 6 02:08:20 2008
@@ -203,14 +203,9 @@
self.cropMax = pos
self.UpdateDMinMax()
self.Refresh()
+
if (self.parent.group != 1): #if not the volumedata
- self.scene.test.setClipMinMax(self.varIndex,
float(self.cropDMin), float(self.cropDMax))
- #max = float(evt.GetPosition().x)/float(self.width)
- #dc.SetBrush(wx.Brush( (0,0,0,56) ) )
- #dc.SetPen(wx.Pen("BLACK", 0) )
- #cropWidth = abs((float(max) -
float(self.cropMin))*float(self.width))
- #dc.DrawRectangle(float(self.cropMin)*float(self.width) , 0,
cropWidth, self.height)
- #self.Refresh()
+ self.scene.test.setClipMinMax(self.varIndex,
float(self.cropDMin - 0.00000001), float(self.cropDMax+ 0.00000001))
#TODO: should get rid of epsilon...
def SetValues(self, datavalues, nbuckets, widthn, heightn):
@@ -265,8 +260,11 @@
def UpdateCropToD(self):
dWidth = self.dMax - self.dMin
- self.cropMin = (self.cropDMin - self.dMin)/dWidth
- self.cropMax = (self.cropDMax - self.dMin)/dWidth
+ if (dWidth == 0):
+ self.cropMin = self.cropMax = 0
+ else:
+ self.cropMin = (self.cropDMin - self.dMin)/dWidth
+ self.cropMax = (self.cropDMax - self.dMin)/dWidth
def Update(self):
@@ -295,7 +293,7 @@
else:
step = 0.0
end = start + step
-
+ print step
if (numBuckets > 0):
barWidth = self.barWidth = float(width)/float(numBuckets)
else:
@@ -322,13 +320,18 @@
# hMax = frequency
#start += step
#end += step
-
+
colorWidth = float(self.colorDMax - self.colorDMin)
croppedHeightValues = int(width)*[0]
for i in range(0,width):
#frequency = len( [x for x in data if (x >= start and x <= end)]
)
- for j in range(int(start), int(end)):
- croppedHeightValues[i] += data[j]
+ start2 = int(start)
+ end2 = int(end)
+ if (start2 == end2):
+ end2 += 1
+ for j in range(start2,end2):
+ if j >= 0 and j < numBuckets:
+ croppedHeightValues[i] += data[j]
start += step
end += step
@@ -384,28 +387,41 @@
self.SetForegroundColour(wx.Colour(255,0,0))
dc.SetPen(wx.Pen(wx.Colour(255,255,255), 1))
dc.SetBrush(wx.Brush(wx.Colour(255,255,255)))
- fontSize = 8
+ fontSize = 10
if self.scene.biggify == True:
fontSize = 12
dc.SetFont(wx.Font(fontSize, wx.FONTFAMILY_DEFAULT, wx.NORMAL,
wx.FONTWEIGHT_BOLD))
- string = str(round(self.cropDMin, 2))
+ string = str("%1.2g" % self.cropDMin)
extent = dc.GetTextExtent(string)
- dc.DrawTextPoint(string, (cropMin*self.width - extent[0]/2.0 +
self.paddingW/2.0,self.height))
- string = str(round(self.cropDMax, 2))
+ xpos = cropMin*self.width - extent[0]/2.0 + self.paddingW/2.0
+ diff = xpos - self.paddingW/2.0
+ if diff < 0:
+ xpos -= diff
+ ypos = self.height-extent[1]
+ dc.DrawTextPoint(string, (xpos,ypos))
+ string = str("%1.2g" % self.cropDMax)
extent = dc.GetTextExtent(string)
- dc.DrawTextPoint(string, (cropMax*self.width - extent[0]/2.0 +
self.paddingW/2.0,self.height))
+ xpos = cropMax*self.width - extent[0]/2.0 + self.paddingW/2.0
+ diff = xpos + extent[0] - (self.width + self.paddingW/2.0)
+ if (diff > 0 ):
+ xpos -= diff
+ dc.DrawTextPoint(string, (xpos,ypos))
#draw min/max text
- textHeight = extent[1]
- ypos = self.height+textHeight-4.0
+ ypos = self.height
if self.scene.biggify:
- ypos = self.height + 4.0
- string = str(round(self.dMin, 2))
+ ypos = self.height
+ string = str("%1.2g" %self.dMin)
extent = dc.GetTextExtent(string)
- dc.DrawTextPoint(string, (self.paddingW/2.0 - extent[0]/2.0,ypos))
- string = str(round(self.dMax, 2))
+ xpos = self.paddingW/2.0
+ dc.DrawTextPoint(string, (xpos,ypos))
+ string = str("%1.2g" % self.dMax)
extent = dc.GetTextExtent(string)
- dc.DrawTextPoint(string, (self.paddingW/2.0 + self.width -
extent[0]/2.0,ypos))
+ xpos = self.width - extent[0]/2.0 + self.paddingW/2.0
+ diff = xpos + extent[0] - (self.width + self.paddingW/2.0)
+ if (diff > 0 ):
+ xpos -= diff
+ dc.DrawTextPoint(string, (xpos,ypos))
def DrawLines(self, dc):
Modified: trunk/scenes/csafe/python/SceneInfo.py
==============================================================================
--- trunk/scenes/csafe/python/SceneInfo.py (original)
+++ trunk/scenes/csafe/python/SceneInfo.py Tue May 6 02:08:20 2008
@@ -31,4 +31,5 @@
self.minX = self.minY = self.minZ = -0.1
self.maxX = self.maxY = self.maxZ = 0.1
self.maxY = 0.2
+ self.histogramBuckets = 300
Modified: trunk/scenes/csafe/python/csafe_demo.py
==============================================================================
--- trunk/scenes/csafe/python/csafe_demo.py (original)
+++ trunk/scenes/csafe/python/csafe_demo.py Tue May 6 02:08:20 2008
@@ -120,10 +120,14 @@
style=wx.OPEN|wx.CHANGE_DIR)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
- dlg2 = wx.TextEntryDialog(self, 'Name of Volume Value (must be
CCVariable, float):', 'Vol', 'Vol')
- dlg2.SetValue('tempIN')
+ choices = []
+ self.scene.test.readUDAHeader(filename)
+ for i in range(self.scene.test.getUDANumVars()):
+ choices.append(str(self.scene.test.getUDAVarName(i)))
+ dlg2 = wx.SingleChoiceDialog(self, 'Name of Volume Value (must
be CCVariable, float):', 'Vol', choices, wx.CHOICEDLG_STYLE)
if dlg2.ShowModal() == wx.ID_OK:
- volName = dlg2.GetValue()
+ volName = dlg2.GetStringSelection()
+ print "volume selected: " + str(volName)
self.scene.test.loadUDA(filename, volName)
t0 = TransferF.TransferF(self, [], 1, "x")
dataMin = -1.1
@@ -135,7 +139,7 @@
histValues1 = []
histValues2 = []
histValues3 = []
- for i in range(0,100):
+ for i in range(0,self.scene.histogramBuckets):
histValues1.append(5)
histValues2.append(5)
histValues3.append(5)
@@ -287,20 +291,20 @@
vol = False
if self.histoGroups[i].group == 1:
vol = True
- histValues1Ptr = SWIGIFYCreateIntArray(100)
+ histValues1Ptr =
SWIGIFYCreateIntArray(self.scene.histogramBuckets)
histValues = []
min = SWIGIFYCreateFloat(0)
max = SWIGIFYCreateFloat(100)
cmin = SWIGIFYCreateFloat(0)
cmax = SWIGIFYCreateFloat(100)
if (vol == False):
- self.test.getHistogram(self.histoGroups[i].varIndex,
100, histValues1Ptr, min, max)
+
self.test.getHistogram(self.histoGroups[i].varIndex,self.scene.histogramBuckets
, histValues1Ptr, min, max)
else:
- self.test.getVolHistogram(100, histValues1Ptr,min,
max)
+
self.test.getVolHistogram(self.scene.histogramBuckets, histValues1Ptr,min,
max)
dataMin = SWIGIFYGetFloat(min)
dataMax = SWIGIFYGetFloat(max)
print "dataMin/max: " + str(dataMin) + " " + str(dataMax)
- for j in range(100):
+ for j in range(self.scene.histogramBuckets):
histValues.append(SWIGIFYGetIntArrayValue(histValues1Ptr, j))
#print histValues[j]
self.histoGroups[i].SetValues(histValues, dataMin, dataMax)
@@ -420,7 +424,7 @@
self.scene.engine = engine
- histValues1Ptr = SWIGIFYCreateIntArray(100)
+ histValues1Ptr = SWIGIFYCreateIntArray(self.scene.histogramBuckets)
histValues1 = []
dataMin1 = -1.1
dataMax1 = 2.2
@@ -429,7 +433,7 @@
dataMin1 = SWIGIFYGetDouble(min)
dataMax1 = SWIGIFYGetDouble(max)
print "datamin: " + str(dataMin1) + " datamax: " + str(dataMax1)
- for i in range(0,100):
+ for i in range(0,self.scene.histogramBuckets):
histValues1.append(5);
scene.getRenderParameters().maxDepth = 5
Modified: trunk/scenes/csafe/src/CDTest.h
==============================================================================
--- trunk/scenes/csafe/src/CDTest.h (original)
+++ trunk/scenes/csafe/src/CDTest.h Tue May 6 02:08:20 2008
@@ -221,10 +221,11 @@
_world = new Group();
if (spheres)
{
- if(_useClippingBBox)
+ _world->add(_sphereAnimation);
+ /*if(_useClippingBBox)
_world->add(_sphereAnimationCut);
else
- _world->add(_sphereAnimation);
+ _world->add(_sphereAnimation);*/
}
if (volume)
_world->add(_volAnimation);
@@ -372,7 +373,12 @@
if (_clipFrames && _endFrame < int(_vols.size()))
_volAnimation->clipFrames(_startFrame,
_endFrame);
}
-
+ void readUDAHeader(string directory)
+ {
+ uda.readUDAHeader(directory);
+ }
+ int getUDANumVars() { return uda.getNumVariables(); }
+ string getUDAVarName(int i) { return
uda.getVarHeader(i).name; }
void loadUDA(string file, string volName)
{
//TODO: clear out existing data
@@ -382,8 +388,11 @@
for (std::vector<UDAReader::Timestep>::iterator itr =
uda.timesteps.begin(); itr != uda.timesteps.end(); itr++)
{
float* sdata = itr->sphereData;
+
for (int i = 0; i < 100; i++)
+ {
cout << "sphere data: " << sdata[i] << endl;
+ }
Group* group = new Group();
RGBAColorMap* cmap = new RGBAColorMap(1);
int ridx = _ridx;
- [Manta] r2252 - in trunk: Core/Util Model/Readers scenes/csafe/python scenes/csafe/src, brownlee, 05/06/2008
Archive powered by MHonArc 2.6.16.