Text archives Help
- From: brownlee@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r2234 - in trunk: Model/Materials Model/Readers scenes/csafe/python scenes/csafe/src
- Date: Thu, 1 May 2008 04:51:38 -0600 (MDT)
Author: brownlee
Date: Thu May 1 04:51:37 2008
New Revision: 2234
Modified:
trunk/Model/Materials/Volume.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/TransferF.py
trunk/scenes/csafe/python/csafe_demo.cfg
trunk/scenes/csafe/python/csafe_demo.py
trunk/scenes/csafe/src/CDGridSpheres.cc
trunk/scenes/csafe/src/CDTest.h
Log:
additional functionality to UDAReader
Modified: trunk/Model/Materials/Volume.h
==============================================================================
--- trunk/Model/Materials/Volume.h (original)
+++ trunk/Model/Materials/Volume.h Thu May 1 04:51:37 2008
@@ -236,7 +236,7 @@
// float cellStepSize, float metersPerUnit);
Volume(GridArray3<T>* data, RGBAColorMap* colorMap, const Vector&
minBound, const Vector& maxBound, double cellStepSize, double metersPerUnit,
int depth, double forceDataMin = -FLT_MAX, double forceDataMax = -FLT_MAX);
virtual ~Volume();
-
+ void setColorMap(RGBAColorMap* map) { _colorMap = map; }
void getMinMax(double* min, double* max){ *min = _dataMin; *max =
_dataMax; }
void computeHistogram(int numBuckets, int* histValues);
virtual void preprocess(const PreprocessContext& context);
Modified: trunk/Model/Readers/UDAReader.cc
==============================================================================
--- trunk/Model/Readers/UDAReader.cc (original)
+++ trunk/Model/Readers/UDAReader.cc Thu May 1 04:51:37 2008
@@ -2,7 +2,14 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <iostream>
+#include <fstream>
#include <cassert>
+#include <iomanip>
+#include <fstream>
+#include <fcntl.h>
+
+
+#include <zlib.h>
using namespace std;
using namespace Manta;
@@ -25,8 +32,9 @@
return st;
}
-void UDAReader::readUDA(string directory)
+void UDAReader::readUDA(string directory, string volumeVarName)
{
+ _volumeVarName = volumeVarName;
string filename;
assert(directory.length());
if (directory[directory.length()-1] != '/')
@@ -69,12 +77,14 @@
}
cur = cur->next;
}
- xmlFreeDoc(doc);
+ xmlFreeDoc(doc);
+ cout << "UDAReader complete\n";
}
void UDAReader::parseTimestepFile(string filename)
{
- UDAReader::Timestep timestep;
+ _timesteps.push_back(Timestep());
+ UDAReader::Timestep& timestep = _timesteps[_timesteps.size()-1];
timestep.dir = parseDirectory(filename);
cout << "Parsing Timestep: " << filename << "\n";
xmlDocPtr doc;
@@ -117,7 +127,7 @@
{
if ((!xmlStrcmp(t->name, (const xmlChar*)"Datafile")))
{
- parseDataFile(string(timestep.dir + string((const
char*)xmlGetProp(t,(const xmlChar*)"href"))));
+ parseDataFile(string(timestep.dir + string((const
char*)xmlGetProp(t,(const xmlChar*)"href"))), timestep);
}
t = t->next;
}
@@ -128,10 +138,286 @@
//cout << "parsing timestep done.\n" << "lower: " <<
timestep.lower.x() << " " << timestep.lower.y() << " " << timestep.lower.z()
<< endl;
//cout << "upper: " << timestep.upper.x() << " " <<
timestep.upper.y() << " " << timestep.upper.z() << endl;
//cout << "indices: " << timestep.indices.x() << " " <<
timestep.indices.y() << " " << timestep.indices.z() << endl;
+ //read in data files
+ int numSpheres = 0;
+ int numSphereVars = 0;
+ for(map<string, vector<VarInfo> >::iterator itr =
timestep.dataMapping.begin(); itr != timestep.dataMapping.end(); itr++)
+ {
+ vector<VarInfo>& vars = timestep.dataMapping[itr->first];
+ //find particles' position first, should be in first 3 indices
+ int tempSphereVars = 0;
+ for (vector<VarInfo>::iterator itr = vars.begin(); itr !=
vars.end(); itr++)
+ {
+ VarInfo& var = (*itr);
+
+ if (var.type == particleVariable)
+ {
+ if (var.dataType == pointT)
+ tempSphereVars += 3;
+ var.dataIndex = 0;
+ numSpheres = max(var.numParticles, numSpheres);
+ }
+ }
+ numSphereVars = max(numSphereVars, tempSphereVars);
+ }
+ timestep.volume->resize(timestep.indices[0]+1,
timestep.indices[1]+1, timestep.indices[2]+1);
+ timestep.numSphereVars = numSphereVars;
+ timestep.numSpheres = numSpheres;
+ cout << "numSphereVars: " << timestep.numSphereVars << endl;
+ cout << "numSpheres: " << timestep.numSpheres << endl;
+ timestep.sphereData = new
float[timestep.numSphereVars*timestep.numSpheres];
+ for(map<string, vector<VarInfo> >::iterator itr =
timestep.dataMapping.begin(); itr != timestep.dataMapping.end(); itr++)
+ {
+ //cout << "reading filename: " << itr->first << endl;
+ readData(itr->first, timestep);
+ }
+ cout << "done parsing timestep\n number of particles read: " <<
timestep.numSpheres <<
+ "\n number of particle variables read in: " <<
timestep.numSphereVars
+ << "\n number of volume indices read in: " <<
timestep.indices[0]+1 << " " <<
+ timestep.indices[1]+1 << " " << timestep.indices[2]+1 << endl;
+ }
+
+Vector UDAReader::readPoint(char* p)
+{
+ double x = *((double*)p);
+ p = p + sizeof(double);
+ double y = *((double*)p);
+ p = p + sizeof(double);
+ double z = *((double*)p);
+ p = p + sizeof(double);
+ return Vector(x,y,z);
+}
+
+float UDAReader::readFloat(char* p)
+{
+ return *((float*)p);
+}
+
+#define SWAP_2(u2)/* IronDoc macro to swap two byte quantity */ \
+ { unsigned char* _p = (unsigned char*)(&(u2)); \
+ unsigned char _c = *_p; *_p = _p[1]; _p[1] = _c; }
+#define SWAP_4(u4)/* IronDoc macro to swap four byte quantity */ \
+ { unsigned char* _p = (unsigned char*)(&(u4)); \
+ unsigned char _c = *_p; *_p = _p[3]; _p[3] = _c; \
+ _c = *++_p; *_p = _p[1]; _p[1] = _c; }
+#define SWAP_8(u8)/* IronDoc macro to swap eight byte quantity */ \
+ { unsigned char* _p = (unsigned char*)(&(u8)); \
+ unsigned char _c = *_p; *_p = _p[7]; _p[7] = _c; \
+ _c = *++_p; *_p = _p[5]; _p[5] = _c; \
+ _c = *++_p; *_p = _p[3]; _p[3] = _c; \
+ _c = *++_p; *_p = _p[1]; _p[1] = _c; }
+
+
+static void swapbytes(bool&) { }
+static void swapbytes(int8_t&) { }
+static void swapbytes(uint8_t&) { }
+static void swapbytes(int16_t& i) { SWAP_2(i); }
+static void swapbytes(uint16_t& i) { SWAP_2(i); }
+static void swapbytes(int32_t& i) { SWAP_4(i); }
+static void swapbytes(uint32_t& i) { SWAP_4(i); }
+static void swapbytes(int64_t& i) { SWAP_8(i); }
+static void swapbytes(uint64_t& i) { SWAP_8(i); }
+static void swapbytes(float& i){SWAP_4(i);}
+static void swapbytes(double& i){SWAP_8(i);}
+//void swapbytes(Point &i){ // probably dangerous, but effective
+// double* p = (double *)(&i);
+// SWAP_8(*p); SWAP_8(*++p); SWAP_8(*++p); }
+static void swapbytes(Vector &i){ // probably dangerous, but effective
+ double* p = (double *)(&i);
+ SWAP_8(*p); SWAP_8(*++p); SWAP_8(*++p); }
+
+
+
+static unsigned long convertSizeType(uint64_t* ssize, bool swapBytes, int
nByteMode)
+{
+ if (nByteMode == 4) {
+ uint32_t size32 = *(uint32_t*)ssize;
+ if (swapBytes) swapbytes(size32);
+ return (unsigned long)size32;
+ }
+ else if (nByteMode == 8) {
+ uint64_t size64 = *(uint64_t*)ssize;
+ if (swapBytes) swapbytes(size64);
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1209 // constant controlling expressions (sizeof)
+#endif
+ if (sizeof(unsigned long) < 8 && size64 > 0xffffffff)
+ throw InternalError("Overflow on 64 to 32 bit conversion");
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1209
+#endif
+
+ return (unsigned long)size64;
+ }
+ else {
+ throw InternalError("Must be 32 or 64 bits");
+ }
+}
+
+
+void UDAReader::readData(string filename, Timestep& t)
+{
+ vector<VarInfo>& vars = t.dataMapping[filename];
+ string file = t.dir + string("l0/") + filename; //TODO: unhardcode the l0
+ //find particles' position first, should be in first 3 indices
+ cout << "reading file: " << file << endl;
+ for (vector<VarInfo>::iterator itr = vars.begin(); itr != vars.end();
itr++)
+ {
+ VarInfo& var = (*itr);
+ if (var.name == _volumeVarName)
+ {
+ var.dataIndex = 0;
+ }
+ }
+ ifstream in(file.c_str(), ios::binary | ios::in);
+ if (!in)
+ return;
+ for (vector<VarInfo>::iterator itr = vars.begin(); itr != vars.end();
itr++)
+ {
+ VarInfo& var = (*itr);
+ if (var.name != _volumeVarName && var.type != particleVariable)
+ continue;
+ in.seekg(var.start);
+ string bufferStr;
+ char* buffer = (char*)bufferStr.c_str();
+ if (var.compressed)
+ {
+ //cerr << "need to compress data\n";
+ int nByteMode = sizeof(float); //TODO: unhardcode!
+ string data;
+ int datasize = var.end-var.start;
+ //string bufferStr;
+ string* uncompressedData = &data;
+ //FILE* ip;
+ //ip = fopen(file.c_str(), "r");
+ //fseek(ip, var.start, 0);
+#ifdef _WIN32
+ int fd = open(file.c_str(), O_RDONLY|O_BINARY);
+#else
+ int fd = open(file.c_str(), O_RDONLY);
+#endif
+ if(fd == -1) {
+ cerr << "Error opening file: " << file.c_str() << '\n';
+ //throw ErrnoException("DataArchive::query (open call)");
+ }
+ off_t ls = lseek(fd, var.start, SEEK_SET);
+
+ if(ls == -1) {
+ cerr << "Error lseek - file: " << file.c_str() << '\n';
+ //throw ErrnoException("DataArchive::query (lseek call)");
+ }
+
+
+ //data.resize(datasize);
+ #ifdef _WIN32
+ // casting from const char* -- use caution
+
+ ssize_t s = ::_read(fd, const_cast<char*>(data.c_str()), datasize);
+ #else
+ ssize_t s = ::read(fd, const_cast<char*>(data.c_str()), datasize);
+ #endif
+
+ if(s != datasize) {
+ cerr << "Error reading file: " << file << '\n';
+ //SCI_THROW(ErrnoException("Variable::read (read call)", errno,
__FILE__, __LINE__));
+ }
+
+ //ic.cur += datasize;
+
+ bool use_gzip = true;
+ bool swapBytes = true;
+ if (use_gzip) {
+ // use gzip compression
+
+ // first read the uncompressed data size
+ istringstream compressedStream(data);
+ uint64_t uncompressed_size_64;
+ compressedStream.read((char*)&uncompressed_size_64, nByteMode);
+
+ unsigned long uncompressed_size =
convertSizeType(&uncompressed_size_64, swapBytes, nByteMode);
+ const char* compressed_data = data.c_str() + nByteMode;
+
+ long compressed_datasize = datasize - (long)(nByteMode);
+
+ // casting from const char* below to char* -- use caution
+ bufferStr.resize(uncompressed_size);
+ buffer = (char*)bufferStr.c_str();
+
+ int result = uncompress( (Bytef*)buffer, &uncompressed_size,
+ (const Bytef*)compressed_data,
compressed_datasize );
+
+ if (result != Z_OK) {
+ printf( "Uncompress error result is %d\n", result );
+ if (result == Z_MEM_ERROR)
+ cout << "not enough memory\n";
+ else if (result == Z_BUF_ERROR)
+ cout << "not enough room in the output buffer\n";
+ else if (result == Z_DATA_ERROR)
+ cout << "input data corrupted\n";
+ //throw InternalError("uncompress failed in
Uintah::Variable::read", __FILE__, __LINE__);
+ }
+
+ uncompressedData = &bufferStr;
+ }
+
+ }
+ else
+ {
+ bufferStr.resize(var.end-var.start + 1);
+ in.read(buffer, var.end-var.start);
+ }
+
+ char* bufferP = buffer;
+ float* sphereDataPtr = t.sphereData;
+ if (var.type == particleVariable)
+ {
+ for (int i = 0; i < var.numParticles; i++)
+ {
+ if (var.dataType == pointT)
+ {
+ 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)
+ {
+ cout << "parsing volume data\n";
+ Patch& p = t.patches[var.patchId];
+ Vector l = p.lowIndex;
+ Vector h = p.highIndex;
+ cout << "l: " << l[0] << " " << l[1] << " " << l[2] <<
+ "\nh: " << h[0] << " " << h[1] << " " << h[2] << endl;
+ cout << "data size: " << bufferStr.length()/4 << endl;
+ for( int x = l[0]; x < h[0]; x++)
+ {
+ for(int y = l[1]; y < h[1]; y++)
+ {
+ for(int z = l[2]; z < h[2]; z++)
+ {
+ float value;
+ if (var.dataType == floatT)
+ {
+ value = readFloat(bufferP);
+ bufferP += sizeof(float);
+ }
+
+ (*(t.volume))(x,y,z) = value;
+ }
+ }
+ }
+ }
}
- void UDAReader::parseDataFile(string filename)
+}
+
+ void UDAReader::parseDataFile(string filename, Timestep& timestep)
{
- // cout << "parsing datafile: " << filename << endl;
+ cout << "parsing datafile: " << filename << endl;
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(filename.c_str());
@@ -150,50 +436,74 @@
xmlFreeDoc(doc);
return;
}
- cur = cur->xmlChildrenNode;
- while (cur != NULL)
+ int numvars = 0;
+ for (cur = cur->xmlChildrenNode; cur != NULL; cur=cur->next)
{
if ((!xmlStrcmp(cur->name, (const xmlChar *)"Variable")))
{
UDAReader::VarInfo v;
xmlNodePtr t = cur->xmlChildrenNode;
+ string type = string((const char*)xmlGetProp(cur,(const
xmlChar*)"type"));
+ //cout << "type: " << type << endl;
+ if (type.find("ParticleVariable") != string::npos)
+ v.type = particleVariable;
+ else if (type.find("CCVariable") != string::npos)
+ v.type = cCVariable;
+ else
+ continue;
+ if (type.find("Point") != string::npos)
+ v.dataType = pointT;
+ else if (type.find("float") != string::npos)
+ v.dataType = floatT;
while (t != NULL)
{
if ((!xmlStrcmp(t->name, (const xmlChar*)"variable")))
{
- v.name = string((const
char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
+ v.name = string((const
char*)xmlNodeListGetString(doc, t->xmlChildrenNode, 1));
}
if ((!xmlStrcmp(t->name, (const xmlChar*)"index")))
{
- stringstream s((const char*)xmlNodeListGetString(doc,
cur->xmlChildrenNode, 1));
+ stringstream s((const char*)xmlNodeListGetString(doc,
t->xmlChildrenNode, 1));
s >> v.index;
}
if ((!xmlStrcmp(t->name, (const xmlChar*)"patch")))
{
- stringstream s((const char*)xmlNodeListGetString(doc,
cur->xmlChildrenNode, 1));
+ stringstream s((const char*)xmlNodeListGetString(doc,
t->xmlChildrenNode, 1));
s >> v.patchId;
}
if ((!xmlStrcmp(t->name, (const xmlChar*)"start")))
{
- stringstream s((const char*)xmlNodeListGetString(doc,
cur->xmlChildrenNode, 1));
+ stringstream s((const char*)xmlNodeListGetString(doc,
t->xmlChildrenNode, 1));
s >> v.start;
}
if ((!xmlStrcmp(t->name, (const xmlChar*)"end")))
{
- stringstream s((const char*)xmlNodeListGetString(doc,
cur->xmlChildrenNode, 1));
+ stringstream s((const char*)xmlNodeListGetString(doc,
t->xmlChildrenNode, 1));
s >> v.end;
}
if ((!xmlStrcmp(t->name, (const xmlChar*)"filename")))
{
- v.filename = string((const
char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
- _dataMapping[v.filename].push_back(v);
+ v.filename = string((const
char*)xmlNodeListGetString(doc, t->xmlChildrenNode, 1));
+ // cout << "adding data filename: " << v.filename <<
endl;
+ }
+ if ((!xmlStrcmp(t->name, (const xmlChar*)"numParticles")))
+ {
+ stringstream s((const char*)xmlNodeListGetString(doc,
t->xmlChildrenNode, 1));
+ s >> v.numParticles;
+ cout << "numParticles: " << s.str() << " " <<
v.numParticles << endl;
+ }
+ if ((!xmlStrcmp(t->name, (const xmlChar*)"compression")))
+ {
+ v.compressed = true;
}
t = t->next;
}
- }
- cur = cur->next;
- }
- xmlFreeDoc(doc);
+ timestep.dataMapping[v.filename].push_back(v);
+ numvars++;
+ }
+ }
+ cout << "numvars read: " << numvars << endl;
+ xmlFreeDoc(doc);
}
@@ -233,7 +543,7 @@
if ((!xmlStrcmp(cur->name, (const xmlChar *)"id")))
{
stringstream s(parseXMLString((const
char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)));
- s >> patch._id;
+ s >> patch.id;
}
if ((!xmlStrcmp(cur->name, (const xmlChar *)"lower")))
{
@@ -269,6 +579,7 @@
}
cur = cur->next;
}
+ timestep.patches[patch.id] = patch;
}
Modified: trunk/Model/Readers/UDAReader.h
==============================================================================
--- trunk/Model/Readers/UDAReader.h (original)
+++ trunk/Model/Readers/UDAReader.h Thu May 1 04:51:37 2008
@@ -18,6 +18,7 @@
#include <string>
#include <sstream>
#include <map>
+#include <Core/Containers/GridArray3.h>
namespace Manta
{
@@ -25,28 +26,44 @@
class UDAReader
{
public:
- UDAReader() {}
- void readUDA(std::string directory);
- void parseTimestepFile(std::string filename);
- void parseDataFile(std::string file);
- struct Timestep
- {
- std::string dir;
- Vector lower, upper, indices;
- };
+ enum { particleVariable, cCVariable, nCVariable, doubleT, floatT,
pointT, vectorT, unknown };
struct VarInfo
{
+ VarInfo() { type = dataType = unknown; compressed = false; dataIndex =
-1;
+ start = end = 0; }
std::string name, filename;
- int start, end, index, patchId, type;
+ int start, end, index, patchId, type, dataType, numParticles,
dataIndex;
+ bool compressed;
};
struct Patch
{
- int _id;
+ int id;
Vector lower, upper, lowIndex, highIndex;
};
+ struct Timestep
+ {
+ Timestep() { sphereData = NULL; volume = new GridArray3<float>();
numSpheres = 0; }
+ std::string dir;
+ Vector lower, upper, indices;
+ std::map <std::string, std::vector<VarInfo> > dataMapping;
+ std::map <int, Patch> patches;
+ GridArray3<float>* volume;
+ float* sphereData;
+ int numSphereVars, numSpheres;
+ };
+
+ UDAReader() {}
+ void readUDA(std::string directory, std::string volumeVarName);
+ void parseTimestepFile(std::string filename);
+ void parseDataFile(std::string file, Timestep& t);
+
private:
+ std::string _volumeVarName;
std::string _directory;
- std::map <std::string, std::vector<VarInfo> > _dataMapping;
+ void readData(std::string filename, Timestep& t);
+ Vector readPoint(char* p);
+ float readFloat(char* p);
+ std::vector<Timestep> _timesteps;
};
}
Modified: trunk/scenes/csafe/python/Configuration.py
==============================================================================
--- trunk/scenes/csafe/python/Configuration.py (original)
+++ trunk/scenes/csafe/python/Configuration.py Thu May 1 04:51:37 2008
@@ -114,7 +114,7 @@
histValues1 = []
for i in range(100):
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, transferFID, name)
+ 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))
histoGroup.group = group
scene.frame.histoGroups.append(histoGroup)
Modified: trunk/scenes/csafe/python/Histogram.py
==============================================================================
--- trunk/scenes/csafe/python/Histogram.py (original)
+++ trunk/scenes/csafe/python/Histogram.py Thu May 1 04:51:37 2008
@@ -204,7 +204,7 @@
self.UpdateDMinMax()
self.Refresh()
if (self.parent.group != 1): #if not the volumedata
- self.scene.test.setClipMinMax(self.varIndex, self.cropDMin,
self.cropDMax)
+ 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) )
@@ -443,7 +443,16 @@
self.height = height
self.group = 0 #0 = spheres, 1 = volume
- self.CreateElements()
+ self.CreateElements()
+
+ def SetTransferF(self, transferF):
+ if (transferF != self.transferF):
+ self.transferF = transferF
+ self.transferFID = transferF.id
+ if self.group == 0:
+ self.scene.test.setSphereCMap(transferF.cmap)
+ else:
+ self.scene.test.setVolCMap(transferF.cmap)
def SetValues(self, histValues, dataMin, dataMax):
self.dataMin = dataMin
@@ -555,10 +564,10 @@
self.histogram.Update()
def OnClickColor(self, evt):
- self.transferFPanel.SetLabel(self.transferF.GetLabel())
+ #self.transferFPanel.SetLabel(self.transferF.GetLabel())
+ self.transferFPanel.transferFPanel.SetHistogramGroup(self)
self.transferFPanel.SetTransferF(self.transferF)
self.transferFPanel.SetUpdateFunction(self.Update())
- self.transferFPanel.transferFPanel.SetHistogram(self.histogram)
if self.varIndex != self.scene.volVar:
self.scene.test.setCidx(self.varIndex)
if (self.transferF != None):
Modified: trunk/scenes/csafe/python/TransferF.py
==============================================================================
--- trunk/scenes/csafe/python/TransferF.py (original)
+++ trunk/scenes/csafe/python/TransferF.py Thu May 1 04:51:37 2008
@@ -21,16 +21,13 @@
class TransferF(wx.Object):
def __init__(self, parent, colorsn, id, title="untitled", cmap = None):
- print "init"
self.parent = parent
self.colors = colorsn
self.id = id
if (cmap != None):
- #slices = cmap.GetColors()
+ self.colors = []
num = cmap.GetNumSlices()
for i in range(num):
- #color = manta_new(vector_ColorSlice())
- #color = slices.at(i).color.color
slice = cmap.GetSlice(i)
c = slice.color.color
a = float(slice.color.a)
@@ -39,16 +36,20 @@
c2 = float(SWIGIFYGetColorValue(c,1))
c3 = float(SWIGIFYGetColorValue(c,2))
self.colors.append((float(p), float(c1), float(c2),
float(c3), float(a)))
+ empty = False
if len(self.colors) < 1.0:
- #print "appending"
+ empty = True
self.colors.append((0.0, 0, 0, 0, 1))
self.colors.append((1.0, 1, 1, 1, 1))
- #self.colors.append((0.5, 0, 1, 1, 1))
- #self.colors.append((0.3, 1, 0, 1, 1))
- #print len(self.colors)
+ if cmap == None:
+ if empty == False:
+ slices = manta_new(vector_ColorSlice())
+ for i in range(len(colorsn)):
+ slices.push_back(ColorSlice(colorsn[0], colorsn[1],
colorsn[2], colorsn[3], colorsn[4]))
+ cmap = manta_new(RGBAColorMap(slices))
+ else:
+ cmap = manta_new(RGBAColorMap(1))
self.colors.sort()
- #for i in range(0, len(self.colors)):
- # print self.colors[i]
self.label = title
self.cmap = cmap
@@ -194,7 +195,10 @@
index = i
if clicked:
- dlg = wx.ColourDialog(self)
+ c = self.transferF.colors[index]
+ color = wx.ColourData()
+ color.SetColour(wx.Colour(c[1]*255, c[2]*255, c[3]*255))
+ dlg = wx.ColourDialog(self, color)
dlg.GetColourData().SetChooseFull(True)
if dlg.ShowModal() == wx.ID_OK:
@@ -249,7 +253,7 @@
self.UpdateHistogram()
- def SetHistogram(self, histo):
+ def SetHistogramGroup(self, histo):
self.histogram = histo
def UpdateHistogram(self):
@@ -348,6 +352,9 @@
def ChooseColorSelected(self):
if self.dSelected != None:
+ c = self.transferF.colors[self.dSelected]
+ color = wx.ColourData()
+ color.SetColour(wx.Colour(c[1]*255, c[2]*255, c[3]*255))
dlg = wx.ColourDialog(self)
dlg.GetColourData().SetChooseFull(True)
@@ -480,7 +487,6 @@
menu.Destroy()
def OnPopUp(self, evt):
- print "popup"
if evt.GetId() == self.puNewID:
dlg = wx.TextEntryDialog(self, 'Set Name of new TF:', 'TF', 'TF')
dlg.SetValue('Untitled')
@@ -517,7 +523,12 @@
def SetTransferF(self, transferF):
self.transferF = transferF
self.transferFPanel.SetTransferF(transferF)
- self.SetLabel(transferF.label)
+ label = transferF.label
+ if self.transferFPanel.histogram != None:
+ label = str(label) + str(" : ") +
str(self.transferFPanel.histogram.title)
+ self.SetLabel(label)
+ if self.transferFPanel.histogram != None:
+ self.transferFPanel.histogram.SetTransferF(transferF)
def SetUpdateFunction(self, function):
print ""
Modified: trunk/scenes/csafe/python/csafe_demo.cfg
==============================================================================
--- trunk/scenes/csafe/python/csafe_demo.cfg (original)
+++ trunk/scenes/csafe/python/csafe_demo.cfg Thu May 1 04:51:37 2008
@@ -191,7 +191,7 @@
[Histogram]
x
-1
+0
0
-0.0613283030689 0.0587040632963
-0.0613283030689 0.0587040632963
@@ -201,7 +201,7 @@
[Histogram]
y
-2
+1
0
3.517361165e-06 0.0709128901362
3.517361165e-06 0.0709128901362
@@ -211,7 +211,7 @@
[Histogram]
z
-3
+2
0
3.00736237129e-12 9.78749994829e-07
3.00736237129e-12 9.78749994829e-07
@@ -221,7 +221,7 @@
[Histogram]
p.mass
-4
+3
0
17.9502124786 5116.43701172
17.9502124786 5116.43701172
@@ -231,7 +231,7 @@
[Histogram]
p.temperature
-5
+4
0
-23199981568.0 13832486912.0
-23199981568.0 13832486912.0
@@ -241,7 +241,7 @@
[Histogram]
p.stress Trace/3
-6
+5
0
2.95434688269e-06 0.000362312624929
2.95434688269e-06 0.000362312624929
@@ -251,7 +251,7 @@
[Histogram]
Radius from p.volume
-8
+6
0
0.0 1.0
0.0 1.0
@@ -261,7 +261,7 @@
[Histogram]
Material Index
-9
+7
0
-3.40282346639e+38 3.40282346639e+38
-3.40282346639e+38 3.40282346639e+38
Modified: trunk/scenes/csafe/python/csafe_demo.py
==============================================================================
--- trunk/scenes/csafe/python/csafe_demo.py (original)
+++ trunk/scenes/csafe/python/csafe_demo.py Thu May 1 04:51:37 2008
@@ -33,8 +33,8 @@
"""
# Import wxManta gui and some system modules.
-import wxversion
-wxversion.ensureMinimal("2.8")
+#import wxversion
+#wxversion.ensureMinimal("2.8")
import wxManta
import getopt, sys
@@ -401,8 +401,22 @@
self.sphereVolCMaps.append(manta_new(RGBAColorMap(1)))
self.t0 = t0 = TransferF.TransferF(self, colors9, 0, "volume",
self.volCMap)
self.defaultTransferF = TransferF.TransferF(self, colors, 1, "empty",
self.sphereVolCMaps[0])
+ t1 = TransferF.TransferF(self, [], 0, "InvRainbowIso",
manta_new(RGBAColorMap(RGBAColorMap.InvRainbowIso)))
+ t2 = TransferF.TransferF(self, [], 0, "InvRainbow",
manta_new(RGBAColorMap(RGBAColorMap.InvRainbow)))
+ t3 = TransferF.TransferF(self, [], 0, "Rainbow",
manta_new(RGBAColorMap(RGBAColorMap.Rainbow)))
+ t4 = TransferF.TransferF(self, [], 0, "InvGreyScale",
manta_new(RGBAColorMap(RGBAColorMap.InvGreyScale)))
+ t5 = TransferF.TransferF(self, [], 0, "InvBlackBody",
manta_new(RGBAColorMap(RGBAColorMap.InvBlackBody)))
+ t6 = TransferF.TransferF(self, [], 0, "BlackBody",
manta_new(RGBAColorMap(RGBAColorMap.BlackBody)))
+ t7 = TransferF.TransferF(self, [], 0, "GreyScale",
manta_new(RGBAColorMap(RGBAColorMap.GreyScale)))
self.transferFunctions = []
self.transferFunctions.append(self.t0)
+ self.transferFunctions.append(t1)
+ self.transferFunctions.append(t2)
+ self.transferFunctions.append(t3)
+ self.transferFunctions.append(t4)
+ self.transferFunctions.append(t5)
+ self.transferFunctions.append(t6)
+ self.transferFunctions.append(t7)
self.tPanel = tPanel = TransferF.TransferFGroup(self.panel, 300, 100,
self.defaultTransferF, "empty", self.scene)
self.scene.tPanel = tPanel
@@ -419,7 +433,7 @@
histoGroup0 = Histogram.HistogramGroup(self.panel, histValues1,
dataMin1, dataMax1, 300, 40.0, t0, tPanel, self.scene, 8, "volume")
histoGroup0.group = 1
histoGroup0.SetBackgroundColour(color)
- tPanel.transferFPanel.SetHistogram(histoGroup0.histogram)
+ tPanel.transferFPanel.SetHistogramGroup(histoGroup0)
self.histoGroups = []
self.histoGroups.append(histoGroup0)
vs.Add(hvs,0,wx.ALIGN_TOP|wx.ALL,1)
Modified: trunk/scenes/csafe/src/CDGridSpheres.cc
==============================================================================
--- trunk/scenes/csafe/src/CDGridSpheres.cc (original)
+++ trunk/scenes/csafe/src/CDGridSpheres.cc Thu May 1 04:51:37 2008
@@ -720,14 +720,17 @@
while (tnear < rays.getMinT(ray_idx)) {
MCell& mcell=mcells[idx];
if (mcell.nspheres > 0) {
+ bool skip = false;
// XXX: Range checking would go here...
Ignore for now
for(int j = 0; j < nvars; j++)
{
if (mcell.min[j] > clipMaxs[j])
- return;
+ { skip = true; break; }
if (mcell.max[j] < clipMins[j])
- return;
+ { skip = true; break; }
}
+ if (!skip)
+ {
// Compute lattice coordinates
int
new_ix=Clamp(static_cast<int>((cellcorner.x() + tnear*celldir.x() -
ix)*ncells), 0, ncells - 1);
@@ -769,6 +772,7 @@
#else
stop_x, stop_y, stop_z);
#endif // USE_OPTIMIZED_FCNS
+ }
}
// March to next macrocell at the current depth
@@ -801,16 +805,25 @@
int start=counts[2*idx];
int nsph=counts[2*idx + 1];
for (int j=0; j<nsph; ++j) {
+ bool skip = false;
float* data=spheres + cells[start + j];
// XXX: Range checking would go here...
Ignore for now
for(int k = 0; k < nvars; k++)
{
if (data[k] < clipMins[k])
+ {
+ skip = true;
break;
+ }
if (data[k] > clipMaxs[k])
+ {
+ skip = true;
break;
+ }
}
+ if(!skip)
+ {
// Sphere is in range, determine it's radius
(squared)
float radius2;
if (ridx>0) {
@@ -831,6 +844,7 @@
intersectSphereDefault(rays, ray_idx, start
+ j,
Vector(data[0], data[1], data[2]), radius2);
#endif
+ }
}
// March to the next cell
Modified: trunk/scenes/csafe/src/CDTest.h
==============================================================================
--- trunk/scenes/csafe/src/CDTest.h (original)
+++ trunk/scenes/csafe/src/CDTest.h Thu May 1 04:51:37 2008
@@ -494,7 +494,13 @@
/*!
\param colormap
*/
- void setVolCMap(RGBAColorMap* map) { _volCMap = map; }
+ void setVolCMap(RGBAColorMap* map) { _volCMap = map;
+ for(vector<Volume<float>*>::iterator i =
_vols.begin(); i != _vols.end(); i++)
+ {
+ (*i)->setColorMap(map);
+
+ }
+ }
//! set the colormap for spheres
/*!
- [Manta] r2234 - in trunk: Model/Materials Model/Readers scenes/csafe/python scenes/csafe/src, brownlee, 05/01/2008
Archive powered by MHonArc 2.6.16.