Changeset 370
- Timestamp:
- Mar 21, 2006 11:00:11 PM (18 years ago)
- Location:
- trunk/src2/core
- Files:
-
- 8 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src2/core/Makefile
r364 r370 1 CFLAGS = -g 1 2 all: viz 2 3 3 viz: viz.o RpOutcome.o RpMesh1D.o RpField1D.o RpMesh Rect3D.o RpFieldRect3D.o4 g++ -g -o viz viz.o RpOutcome.o RpMesh1D.o RpField1D.o RpMeshRect3D.o RpFieldRect3D.o4 viz: viz.o RpOutcome.o RpMesh1D.o RpField1D.o RpMeshTri2D.o RpMeshRect3D.o RpFieldRect3D.o RpMeshPrism3D.o RpFieldPrism3D.o RpSerialBuffer.o RpSerializer.o RpSerializable.o 5 g++ $(CFLAGS) -o viz viz.o RpOutcome.o RpMesh1D.o RpField1D.o RpMeshTri2D.o RpMeshRect3D.o RpFieldRect3D.o RpMeshPrism3D.o RpFieldPrism3D.o RpSerialBuffer.o RpSerializer.o RpSerializable.o 5 6 6 7 viz.o: viz.cc 7 g++ -c -g-o viz.o viz.cc8 g++ $(CFLAGS) -c -o viz.o viz.cc 8 9 9 test: test.o RpOutcome.o RpMesh1D.o RpField1D.o RpMesh Rect3D.o RpFieldRect3D.o RpSerialBuffer.o10 g++ -g -o test test.o RpOutcome.o RpMesh1D.o RpField1D.o RpMeshRect3D.o RpFieldRect3D.o RpSerialBuffer.o10 test: test.o RpOutcome.o RpMesh1D.o RpField1D.o RpMeshTri2D.o RpFieldTri2D.o RpMeshRect3D.o RpFieldRect3D.o RpMeshPrism3D.o RpFieldPrism3D.o RpSerialBuffer.o RpSerializer.o RpSerializable.o 11 g++ $(CFLAGS) -o test test.o RpOutcome.o RpMesh1D.o RpField1D.o RpMeshTri2D.o RpFieldTri2D.o RpMeshRect3D.o RpFieldRect3D.o RpMeshPrism3D.o RpFieldPrism3D.o RpSerialBuffer.o RpSerializer.o RpSerializable.o 11 12 12 13 test.o: test.cc RpPtr.h 13 g++ -c -g-o test.o test.cc14 g++ $(CFLAGS) -c -o test.o test.cc 14 15 15 16 RpOutcome.o: RpOutcome.cc RpPtr.h 16 g++ -c -g-o RpOutcome.o RpOutcome.cc17 g++ $(CFLAGS) -c -o RpOutcome.o RpOutcome.cc 17 18 18 19 RpMesh1D.o: RpMesh1D.cc RpMesh1D.h RpNode.h 19 g++ -c -g-o RpMesh1D.o RpMesh1D.cc20 g++ $(CFLAGS) -c -o RpMesh1D.o RpMesh1D.cc 20 21 21 22 RpField1D.o: RpField1D.cc RpField1D.h RpMesh1D.h RpNode.h 22 g++ -c -g -o RpField1D.o RpField1D.cc 23 g++ $(CFLAGS) -c -o RpField1D.o RpField1D.cc 24 25 RpMeshTri2D.o: RpMeshTri2D.cc RpMeshTri2D.h RpNode.h 26 g++ $(CFLAGS) -c -o RpMeshTri2D.o RpMeshTri2D.cc 27 28 RpFieldTri2D.o: RpFieldTri2D.cc RpFieldTri2D.h RpNode.h 29 g++ $(CFLAGS) -c -o RpFieldTri2D.o RpFieldTri2D.cc 23 30 24 31 RpMeshRect3D.o: RpMeshRect3D.cc RpMeshRect3D.h RpNode.h 25 g++ -c -g-o RpMeshRect3D.o RpMeshRect3D.cc32 g++ $(CFLAGS) -c -o RpMeshRect3D.o RpMeshRect3D.cc 26 33 27 34 RpFieldRect3D.o: RpFieldRect3D.cc RpFieldRect3D.h RpNode.h 28 g++ -c -g -o RpFieldRect3D.o RpFieldRect3D.cc 35 g++ $(CFLAGS) -c -o RpFieldRect3D.o RpFieldRect3D.cc 36 37 RpMeshPrism3D.o: RpMeshPrism3D.cc RpMeshPrism3D.h RpNode.h 38 g++ $(CFLAGS) -c -o RpMeshPrism3D.o RpMeshPrism3D.cc 39 40 RpFieldPrism3D.o: RpFieldPrism3D.cc RpFieldPrism3D.h RpNode.h 41 g++ $(CFLAGS) -c -o RpFieldPrism3D.o RpFieldPrism3D.cc 29 42 30 43 RpSerialBuffer.o: RpSerialBuffer.cc RpSerialBuffer.h 31 g++ -c -g -o RpSerialBuffer.o RpSerialBuffer.cc 44 g++ $(CFLAGS) -c -o RpSerialBuffer.o RpSerialBuffer.cc 45 46 RpSerializer.o: RpSerializer.cc RpSerializer.h 47 g++ $(CFLAGS) -c -o RpSerializer.o RpSerializer.cc 32 48 33 49 RpSerializable.o: RpSerializable.cc RpSerializable.h 34 g++ -c -g-o RpSerializable.o RpSerializable.cc50 g++ $(CFLAGS) -c -o RpSerializable.o RpSerializable.cc 35 51 36 52 clean: -
trunk/src2/core/RpField1D.cc
r364 r370 88 88 89 89 Node1D& 90 Field1D:: nodeAt(int pos)90 Field1D::atNode(int pos) 91 91 { 92 92 return _meshPtr->at(pos); -
trunk/src2/core/RpField1D.h
r364 r370 36 36 37 37 virtual int size() const; 38 virtual Node1D& nodeAt(int pos);38 virtual Node1D& atNode(int pos); 39 39 virtual double rangeMin() const; 40 40 virtual double rangeMax() const; -
trunk/src2/core/RpFieldRect3D.cc
r364 r370 31 31 { 32 32 _meshPtr = Ptr<MeshRect3D>( new MeshRect3D(xg,yg,zg) ); 33 int npts = xg.size()*yg.size()*zg.size(); 34 _valuelist.reserve(npts); 33 35 } 34 36 … … 46 48 _meshPtr = field._meshPtr; 47 49 _counter = field._counter; 50 return *this; 48 51 } 49 52 … … 55 58 FieldRect3D::size(Axis which) const 56 59 { 57 if (!_meshPtr.is null()) {60 if (!_meshPtr.isNull()) { 58 61 return _meshPtr->size(which); 59 62 } … … 62 65 63 66 Node1D& 64 FieldRect3D:: nodeAt(Axis which, int pos)67 FieldRect3D::atNode(Axis which, int pos) 65 68 { 66 69 static Node1D null(0.0); 67 70 68 if (!_meshPtr.is null()) {71 if (!_meshPtr.isNull()) { 69 72 return _meshPtr->at(which, pos); 70 73 } … … 75 78 FieldRect3D::rangeMin(Axis which) const 76 79 { 77 if (!_meshPtr.is null()) {80 if (!_meshPtr.isNull()) { 78 81 return _meshPtr->rangeMin(which); 79 82 } … … 84 87 FieldRect3D::rangeMax(Axis which) const 85 88 { 86 if (!_meshPtr.is null()) {89 if (!_meshPtr.isNull()) { 87 90 return _meshPtr->rangeMax(which); 88 91 } … … 93 96 FieldRect3D::define(int nodeId, double f) 94 97 { 95 while (_valuelist.size() <= nodeId) {96 _valuelist.push_back(0.0);97 }98 98 _valuelist[nodeId] = f; 99 99 return *this; … … 101 101 102 102 double 103 FieldRect3D::value(double x, double y, double z ) const103 FieldRect3D::value(double x, double y, double z, double outside) const 104 104 { 105 105 double f0, f1, fy0, fy1, fz0, fz1; 106 106 107 if (!_meshPtr.is null()) {107 if (!_meshPtr.isNull()) { 108 108 CellRect3D cell = _meshPtr->locate(Node3D(x,y,z)); 109 110 // outside the defined data? then return the outside value 111 if (cell.isOutside()) { 112 return outside; 113 } 109 114 110 115 // yuck! brute force... … … 138 143 return _interpolate(cell.z(0),fz0, cell.z(4),fz1, z); 139 144 } 140 return 0.0;145 return outside; 141 146 } 142 147 -
trunk/src2/core/RpFieldRect3D.h
r364 r370 17 17 #define RAPPTURE_FIELDRECT3D_H 18 18 19 #include <math.h> 20 #include <vector> 19 21 #include "RpPtr.h" 20 22 #include "RpMeshRect3D.h" … … 31 33 32 34 virtual int size(Axis which) const; 33 virtual Node1D& nodeAt(Axis which, int pos);35 virtual Node1D& atNode(Axis which, int pos); 34 36 virtual double rangeMin(Axis which) const; 35 37 virtual double rangeMax(Axis which) const; 36 38 37 39 virtual FieldRect3D& define(int nodeId, double f); 38 virtual double value(double x, double y, double z) const; 40 virtual double value(double x, double y, double z, 41 double outside=NAN) const; 39 42 40 43 protected: … … 43 46 44 47 private: 45 std:: deque<double> _valuelist;// list of all values, in nodeId order48 std::vector<double> _valuelist; // list of all values, in nodeId order 46 49 Ptr<MeshRect3D> _meshPtr; // mesh for all (x,y,z) points 47 50 int _counter; // counter for generating node IDs -
trunk/src2/core/RpMesh1D.cc
r364 r370 22 22 23 23 // serialization version 'A' for Mesh1D... 24 ////SerialConverter Mesh1D::versionA("Mesh1D", 'A', 25 //// Mesh1D::serialize_A, Mesh1D::create, Mesh1D::deserialize_A); 24 SerialConversion Mesh1D::versionA("Mesh1D", 'A', 25 (Serializable::serializeObjectMethod)&Mesh1D::serialize_A, 26 &Mesh1D::create, 27 (Serializable::deserializeObjectMethod)&Mesh1D::deserialize_A); 26 28 27 29 … … 52 54 assert(n >= 0 && n < 2); 53 55 return _x[n]; 56 } 57 58 int 59 Cell1D::isOutside() const 60 { 61 return (_nodeIds[0] < 0 || _nodeIds[1] < 0); 54 62 } 55 63 … … 317 325 } 318 326 319 ////void 320 ////Mesh1D::serialize_A(SerialBuffer& buffer) const 321 ////{ 322 ////} 323 324 ////Ptr<Serializable> 325 ////Mesh1D::create() 326 ////{ 327 //// return Ptr<Serializable>( new Mesh1D() ); 328 ////} 329 330 ////Outcome 331 ////Mesh1D::deserialize_A(SerialBuffer& buffer) 332 ////{ 333 ////} 327 Ptr<Serializable> 328 Mesh1D::create() 329 { 330 return Ptr<Serializable>( (Serializable*) new Mesh1D() ); 331 } 332 333 void 334 Mesh1D::serialize_A(SerialBuffer& buffer) const 335 { 336 Mesh1D* nonconst = (Mesh1D*)this; 337 buffer.writeInt(_nodelist.size()); 338 339 std::deque<Node1D>::iterator iter = nonconst->_nodelist.begin(); 340 while (iter != _nodelist.end()) { 341 buffer.writeInt( (*iter).id() ); 342 buffer.writeDouble( (*iter).x() ); 343 ++iter; 344 } 345 buffer.writeInt(_counter); 346 } 347 348 Outcome 349 Mesh1D::deserialize_A(SerialBuffer& buffer) 350 { 351 Outcome status; 352 Node1D newnode(0.0); 353 354 clear(); 355 int npts = buffer.readInt(); 356 357 for (int n=0; n < npts; n++) { 358 newnode.id( buffer.readInt() ); 359 newnode.x( buffer.readDouble() ); 360 _nodelist.push_back(newnode); 361 } 362 _counter = buffer.readInt(); 363 364 return status; 365 } -
trunk/src2/core/RpMesh1D.h
r364 r370 21 21 #include <deque> 22 22 #include "RpNode.h" 23 ////#include "RpSerializable.h"23 #include "RpSerializable.h" 24 24 25 25 namespace Rappture { … … 32 32 double& x(int n); 33 33 34 int isOutside() const; 35 34 36 private: 35 37 int _nodeIds[2]; … … 37 39 }; 38 40 39 class Mesh1D {41 class Mesh1D : public Serializable { 40 42 public: 41 43 Mesh1D(); … … 61 63 char serializerVersion() const { return 'A'; } 62 64 63 ////void serialize_A(SerialBuffer& buffer) const;64 ////static Ptr<Serializable> create();65 ////Outcome deserialize_A(SerialBuffer& buffer);65 void serialize_A(SerialBuffer& buffer) const; 66 static Ptr<Serializable> create(); 67 Outcome deserialize_A(SerialBuffer& buffer); 66 68 67 69 protected: … … 77 79 78 80 // methods for serializing/deserializing version 'A' 79 ////static SerialConversion versionA;81 static SerialConversion versionA; 80 82 }; 81 83 -
trunk/src2/core/RpMeshRect3D.cc
r364 r370 78 78 } 79 79 80 int 81 CellRect3D::isOutside() const 82 { 83 for (int i=0; i < 8; i++) { 84 if (_nodeIds[i] < 0) { 85 return 1; 86 } 87 } 88 return 0; 89 } 90 80 91 81 92 MeshRect3D::MeshRect3D() … … 175 186 coord.x(node.z()); 176 187 cells[2] = _axis[2].locate(coord); 177 178 // any of these cells on the edge? then set both sides to edge point179 for (int c=0; c < 3; c++) {180 if (cells[c].nodeId(0) < 0) {181 cells[c].nodeId(0) = cells[c].nodeId(1);182 cells[c].x(0) = cells[c].x(1);183 }184 else if (cells[c].nodeId(1) < 0) {185 cells[c].nodeId(1) = cells[c].nodeId(0);186 cells[c].x(1) = cells[c].x(0);187 }188 }189 188 190 189 int n = 0; … … 195 194 int ny = cells[1].nodeId(iy); 196 195 int nz = cells[2].nodeId(iz); 197 result.nodeId(n) = nz*(_axis[0].size()*_axis[1].size()) 198 + ny*(_axis[0].size()) 199 + nx; 200 201 result.x(n) = cells[0].x(ix); 202 result.y(n) = cells[1].x(iy); 203 result.z(n) = cells[2].x(iz); 196 if (nx >= 0 && ny >= 0 && nz >= 0) { 197 result.nodeId(n) = nz*(_axis[0].size()*_axis[1].size()) 198 + ny*(_axis[0].size()) 199 + nx; 200 result.x(n) = cells[0].x(ix); 201 result.y(n) = cells[1].x(iy); 202 result.z(n) = cells[2].x(iz); 203 } 204 204 n++; 205 205 } -
trunk/src2/core/RpMeshRect3D.h
r364 r370 21 21 namespace Rappture { 22 22 23 enum Axis {xaxis=0, yaxis, zaxis};24 25 23 class CellRect3D { 26 24 public: … … 32 30 double& y(int n); 33 31 double& z(int n); 32 33 int isOutside() const; 34 34 35 35 private: -
trunk/src2/core/RpNode.h
r364 r370 20 20 21 21 namespace Rappture { 22 23 enum Axis {xaxis=0, yaxis, zaxis}; 22 24 23 25 class Node { -
trunk/src2/core/RpOutcome.cc
r364 r370 76 76 { 77 77 _status &= oc._status; 78 if (!oc._contextPtr.is null()) {78 if (!oc._contextPtr.isNull()) { 79 79 _remarkPtr = oc._remarkPtr; 80 80 _contextPtr = oc._contextPtr; … … 85 85 Outcome::remark() const 86 86 { 87 if (!_remarkPtr.is null()) {87 if (!_remarkPtr.isNull()) { 88 88 return _remarkPtr->data(); 89 89 } … … 94 94 Outcome::addContext(const char *rem) 95 95 { 96 if (_contextPtr.is null()) {96 if (_contextPtr.isNull()) { 97 97 _contextPtr = new std::string(); 98 98 } … … 105 105 Outcome::context() const 106 106 { 107 if (!_contextPtr.is null()) {107 if (!_contextPtr.isNull()) { 108 108 return _contextPtr->data(); 109 109 } -
trunk/src2/core/RpPtr.h
r364 r370 87 87 class Ptr { 88 88 public: 89 explicit Ptr(Type* ptr );89 explicit Ptr(Type* ptr=NULL); 90 90 Ptr(const Ptr& ptr); 91 91 Ptr& operator=(Type* ptr); … … 93 93 ~Ptr(); 94 94 95 int is null() const;95 int isNull() const; 96 96 Type* operator->() const; 97 97 Type* pointer() const; 98 Type& operator*() const; 98 99 void clear(); 99 100 … … 154 155 template <class Type> 155 156 int 156 Ptr<Type>::is null() const157 Ptr<Type>::isNull() const 157 158 { 158 159 if (_pc) { … … 183 184 184 185 template <class Type> 186 Type& 187 Ptr<Type>::operator*() const 188 { 189 assert(_pc != NULL); 190 return *(Type*)_pc->pointer(); 191 } 192 193 template <class Type> 185 194 void 186 195 Ptr<Type>::clear() -
trunk/src2/core/RpSerializable.cc
r364 r370 21 21 22 22 // initialize the global lists of registered serialization helper funcs 23 Serializable::_name2createFunc = NULL; 24 Serializable::_name2desMethod = NULL; 23 Serializable::Name2ConvFuncsMap* Serializable::_name2convFuncs = NULL; 25 24 26 25 Serializable::Serializable() … … 42 41 cname += serializerVersion(); 43 42 44 ConversionFuncs& cfuncs = (*_name2convFuncs)[cname];45 this->(cfuncs.serialMethod)(buffer);43 Serializable::ConversionFuncs& cfuncs = (*_name2convFuncs)[cname]; 44 (this->*(cfuncs.serialMethod))(buffer); 46 45 } 47 46 48 47 Outcome 49 Serializable::deserialize(SerialBuffer& buffer, Ptr<Serializable> & objPtr)48 Serializable::deserialize(SerialBuffer& buffer, Ptr<Serializable>* objPtrPtr) 50 49 { 51 50 Outcome result; … … 66 65 67 66 ConversionFuncs& cfuncs = (*_name2convFuncs)[type]; 68 objPtr = (cfuncs.createFunc)(); 69 return objPtr->(cfuncs.deserialMethod)(buffer); 67 *objPtrPtr = (cfuncs.createFunc)(); 68 69 Serializable *objPtr = objPtrPtr->pointer(); 70 return (objPtr->*(cfuncs.deserialMethod))(buffer); 70 71 } 71 72 72 SerialConversion::SerialConversion(const char *class , char version,73 Serializable::serializeObjectMethod serMethod )73 SerialConversion::SerialConversion(const char *className, char version, 74 Serializable::serializeObjectMethod serMethod, 74 75 Serializable::createObjectFunc createFunc, 75 76 Serializable::deserializeObjectMethod desMethod) 76 77 { 77 if (Serializ er::_name2convFuncs == NULL) {78 Serializ er::_name2convFuncs = new Name2ConvFuncsMap;78 if (Serializable::_name2convFuncs == NULL) { 79 Serializable::_name2convFuncs = new Serializable::Name2ConvFuncsMap(); 79 80 } 80 81 81 82 // register the conversion functions for this version 82 std::string vname(class );83 std::string vname(className); 83 84 vname += ":"; 84 85 vname += version; 85 86 86 ConversionFuncs& funcs = (*_name2convFuncs)[vname]; 87 Serializable::ConversionFuncs& funcs 88 = (*Serializable::_name2convFuncs)[vname]; 87 89 88 90 funcs.version = version; … … 92 94 93 95 // if this is the latest version, register it as "current" 94 std::string cname(class );96 std::string cname(className); 95 97 cname += ":current"; 96 98 97 Name2ConvFuncsMap::iterator iter = _name2convFuncs->find(cname); 98 if (iter == _name2convFuncs->end()) { 99 Serializable::Name2ConvFuncsMap::iterator iter 100 = Serializable::_name2convFuncs->find(cname); 101 102 if (iter == Serializable::_name2convFuncs->end()) { 99 103 // this is the first -- register it as "current" 100 ConversionFuncs& cfuncs = (*_name2convFuncs)[cname]; 104 Serializable::ConversionFuncs& cfuncs 105 = (*Serializable::_name2convFuncs)[cname]; 101 106 cfuncs.version = version; 102 107 cfuncs.serialMethod = serMethod; … … 104 109 cfuncs.deserialMethod = desMethod; 105 110 } else { 106 ConversionFuncs& cfuncs = (*_name2convFuncs)[cname]; 111 Serializable::ConversionFuncs& cfuncs 112 = (*Serializable::_name2convFuncs)[cname]; 113 107 114 if (cfuncs.version < version) { 108 115 // this is the latest -- register it as "current" -
trunk/src2/core/RpSerializable.h
r364 r370 21 21 #include <string> 22 22 #include <map> 23 #include "RpPtr.h" 24 #include "RpOutcome.h" 23 25 #include "RpSerialBuffer.h" 24 26 … … 32 34 virtual ~Serializable(); 33 35 34 virtual const char* serializerType() = 0;35 virtual char serializerVersion() = 0;36 virtual const char* serializerType() const = 0; 37 virtual char serializerVersion() const = 0; 36 38 37 39 virtual void serialize(SerialBuffer& bufferPtr) const; 38 static Outcome deserialize(SerialBuffer& buffer, Ptr<Serializable>& objPtr); 40 static Outcome deserialize(SerialBuffer& buffer, Ptr<Serializable>* objPtrPtr); 41 42 typedef void (Serializable::*serializeObjectMethod)(SerialBuffer& buffer) const; 43 typedef Ptr<Serializable> (*createObjectFunc)(); 44 typedef Outcome (Serializable::*deserializeObjectMethod)(SerialBuffer& buffer); 39 45 40 46 private: 41 47 friend class SerialConversion; 42 48 43 typedef void serializeObjectMethod(SerialBuffer& buffer) const; 44 typedef static Ptr<Serializable> createObjectFunc(); 45 typedef Outcome deserializeObjectMethod(SerialBuffer& buffer); 46 47 struct ConversionFuncs { 49 class ConversionFuncs { 50 public: 48 51 char version; 49 52 serializeObjectMethod serialMethod; … … 52 55 }; 53 56 54 typedef map<std::string, ConversionFuncs> Name2ConvFuncsMap;57 typedef std::map<std::string, ConversionFuncs> Name2ConvFuncsMap; 55 58 static Name2ConvFuncsMap *_name2convFuncs; 56 59 }; … … 58 61 class SerialConversion { 59 62 public: 60 SerialConversion(const char *class , char version,63 SerialConversion(const char *className, char version, 61 64 Serializable::serializeObjectMethod, 62 65 Serializable::createObjectFunc, -
trunk/src2/core/RpSerializer.cc
r364 r370 73 73 74 74 // if there was an error, then bail out 75 if ( !result) {75 if (result != 0) { 76 76 std::ostringstream context; 77 77 context << "while deserializing object #" << i+1 78 78 << " of " << nobj; 79 return result.addContext(context.str() );79 return result.addContext(context.str().data()); 80 80 } 81 81 … … 106 106 bufferPtr->writeString("RpObj:"); 107 107 bufferPtr->writeString(id); 108 objPtr->serialize( bufferPtr);108 objPtr->serialize(*bufferPtr.pointer()); 109 109 } 110 110 return bufferPtr; … … 120 120 Serializer::get(int pos) const 121 121 { 122 Serializer *nonconst = (Serializer*)this; 122 123 assert(pos >= 0 && pos < _idlist.size()); 123 124 124 125 std::string id(_idlist[pos]); 125 return _id2obj[id];126 return nonconst->_id2obj[id]; 126 127 } 127 128 … … 134 135 135 136 const char* 136 Serializer:: register(Ptr<Serializable>objPtr)137 Serializer::add(Serializable* objPtr) 137 138 { 138 139 const char* key = NULL; … … 140 141 // build a unique string that represents this object 141 142 std::ostringstream idbuffer; 142 idbuffer << (void*)objPtr .pointer();143 idbuffer << (void*)objPtr; 143 144 std::string id(idbuffer.str()); 144 145 … … 147 148 if (iter == _id2obj.end()) { 148 149 // if not, then add to map and also to list of all objects 149 _id2obj[id] = objPtr;150 _id2obj[id] = Ptr<Serializable>(objPtr); 150 151 iter = _id2obj.find(id); 151 152 key = (*iter).first.data(); … … 154 155 // if so, then update map 155 156 key = (*iter).first.data(); 156 _id2obj[id] = objPtr;157 _id2obj[id] = Ptr<Serializable>(objPtr); 157 158 } 158 159 return key; -
trunk/src2/core/RpSerializer.h
r364 r370 21 21 #include <map> 22 22 #include "RpPtr.h" 23 #include "RpOutcome.h" 23 24 #include "RpSerialBuffer.h" 25 #include "RpSerializable.h" 24 26 25 27 namespace Rappture { … … 30 32 virtual ~Serializer(); 31 33 34 virtual Ptr<SerialBuffer> serialize(); 32 35 virtual Outcome deserialize(const char* bytes, int nbytes); 33 virtual Ptr<SerialBuffer> serialize();34 36 35 37 virtual int size() const; … … 37 39 38 40 virtual Serializer& clear(); 39 virtual const char* register(Ptr<Serializable>objPtr);41 virtual const char* add(Serializable* objPtr); 40 42 41 43 private: … … 48 50 49 51 // map each id in _idlist to the corresponding object 50 typedef std::map<std::string, Ptr<Serializable> > SerializerId2Obj;52 typedef std::map<std::string, Ptr<Serializable> > SerializerId2Obj; 51 53 SerializerId2Obj _id2obj; 52 54 }; -
trunk/src2/core/test.cc
r364 r370 6 6 #include "RpNode.h" 7 7 #include "RpField1D.h" 8 #include "RpMeshTri2D.h" 9 #include "RpFieldTri2D.h" 8 10 #include "RpMeshRect3D.h" 9 11 #include "RpFieldRect3D.h" 12 #include "RpMeshPrism3D.h" 13 #include "RpFieldPrism3D.h" 10 14 #include "RpSerialBuffer.h" 11 ////#include "RpSerializable.h"15 #include "RpSerializer.h" 12 16 13 17 class Foo { … … 67 71 std::cout << "@ 8.8 = " << f.value(8.8) << std::endl; 68 72 69 Rappture::SerialBuffer buffer; 70 buffer.writeChar('a'); 71 buffer.writeInt(1051); 72 buffer.writeDouble(2.51e12); 73 buffer.writeString("xyz"); 74 buffer.writeString("pdq"); 75 76 buffer.rewind(); 77 std::cout << "buffer: "; 78 std::cout << buffer.readChar() << " "; 79 std::cout << buffer.readInt() << " "; 80 std::cout << buffer.readDouble() << " "; 81 std::cout << buffer.readString() << " "; 82 std::cout << buffer.readString() << std::endl; 83 84 Rappture::Mesh1D uni(1.0,5.0,16); 85 showmesh(uni); 73 Rappture::Ptr<Rappture::Mesh1D> uni( 74 new Rappture::Mesh1D(1.0,5.0,16) 75 ); 76 showmesh(*uni); 86 77 87 78 Rappture::Mesh1D uniy(0.0,2.0,10); 88 79 Rappture::Mesh1D uniz(-1.0,1.0,20); 89 80 Rappture::Ptr<Rappture::MeshRect3D> m3dPtr( 90 new Rappture::MeshRect3D( uni, uniy, uniz)81 new Rappture::MeshRect3D(*uni, uniy, uniz) 91 82 ); 92 Rappture::FieldRect3D f3d(m3dPtr); 83 Rappture::Ptr<Rappture::FieldRect3D> f3d( 84 new Rappture::FieldRect3D(*uni, uniy, uniz) 85 ); 93 86 94 87 int n=0; 95 for (int iz=0; iz < f3d .size(Rappture::zaxis); iz++) {96 double zval = f3d .nodeAt(Rappture::zaxis, iz).x();97 for (int iy=0; iy < f3d .size(Rappture::yaxis); iy++) {98 double yval = f3d .nodeAt(Rappture::yaxis, iy).x();99 for (int ix=0; ix < f3d .size(Rappture::xaxis); ix++) {100 double xval = f3d .nodeAt(Rappture::xaxis, ix).x();101 f3d .define(n++, xval*yval*zval);88 for (int iz=0; iz < f3d->size(Rappture::zaxis); iz++) { 89 double zval = f3d->atNode(Rappture::zaxis, iz).x(); 90 for (int iy=0; iy < f3d->size(Rappture::yaxis); iy++) { 91 double yval = f3d->atNode(Rappture::yaxis, iy).x(); 92 for (int ix=0; ix < f3d->size(Rappture::xaxis); ix++) { 93 double xval = f3d->atNode(Rappture::xaxis, ix).x(); 94 f3d->define(n++, xval*yval*zval); 102 95 } 103 96 } 104 97 } 105 98 106 std::cout << "at (1,0,-0.5) " << f3d .value(1.0,0.0,-0.5) << std::endl;107 std::cout << "at (2,1,-0.5) " << f3d .value(2.0,1.0,-0.5) << std::endl;108 std::cout << "at (3,0.7,-0.2) " << f3d .value(3.0,0.7,-0.2) << std::endl;109 std::cout << "at (5,2,1) " << f3d .value(5.0,2.0,1.0) << std::endl;99 std::cout << "at (1,0,-0.5) " << f3d->value(1.0,0.0,-0.5) << std::endl; 100 std::cout << "at (2,1,-0.5) " << f3d->value(2.0,1.0,-0.5) << std::endl; 101 std::cout << "at (3,0.7,-0.2) " << f3d->value(3.0,0.7,-0.2) << std::endl; 102 std::cout << "at (5,2,1) " << f3d->value(5.0,2.0,1.0) << std::endl; 110 103 111 Rappture::Ptr<Foo> ptr3(new Foo("q"));112 std::ostringstream ss;113 ss << (void*)ptr3.pointer();114 std::cout << ss << std::endl;115 104 116 Rappture::Outcome status = foo(1); 117 if (status) { 118 status.addContext("while in main program"); 119 std::cout << status.remark() << std::endl; 120 std::cout << status.context() << std::endl; 105 Rappture::MeshTri2D m2d; 106 m2d.addNode( Rappture::Node2D(0.0,0.0) ); 107 m2d.addNode( Rappture::Node2D(1.0,0.0) ); 108 m2d.addNode( Rappture::Node2D(0.0,1.0) ); 109 m2d.addNode( Rappture::Node2D(1.0,1.0) ); 110 m2d.addNode( Rappture::Node2D(2.0,0.0) ); 111 m2d.addNode( Rappture::Node2D(2.0,1.0) ); 112 m2d.addCell(0,1,2); 113 m2d.addCell(1,2,3); 114 m2d.addCell(1,3,4); 115 m2d.addCell(3,4,5); 116 117 Rappture::FieldTri2D f2d(m2d); 118 f2d.define(0, 0.0); 119 f2d.define(1, 1.0); 120 f2d.define(2, 1.0); 121 f2d.define(3, 4.0); 122 f2d.define(4, 2.0); 123 f2d.define(5, 2.0); 124 std::cout << "value @(0.1,0.1): " << f2d.value(0.1,0.1) << std::endl; 125 std::cout << "value @(0.99,0.99): " << f2d.value(0.99,0.99) << std::endl; 126 std::cout << "value @(1.99,0.01): " << f2d.value(1.99,0.01) << std::endl; 127 std::cout << "value @(2.01,0.02): " << f2d.value(2.01,1.02) << std::endl; 128 129 Rappture::FieldPrism3D fp3d(m2d, uniy); 130 for (int i=0; i < 10; i++) { 131 fp3d.define(i*6+0, (i+1)*0.0); 132 fp3d.define(i*6+1, (i+1)*1.0); 133 fp3d.define(i*6+2, (i+1)*1.0); 134 fp3d.define(i*6+3, (i+1)*4.0); 135 fp3d.define(i*6+4, (i+1)*2.0); 136 fp3d.define(i*6+5, (i+1)*2.0); 137 } 138 std::cout << "value @(0.1,0.1,0.01): " << fp3d.value(0.1,0.1,0.01) << std::endl; 139 std::cout << "value @(0.1,0.1,0.21): " << fp3d.value(0.1,0.1,0.21) << std::endl; 140 std::cout << "value @(0.1,0.1,0.41): " << fp3d.value(0.1,0.1,0.41) << std::endl; 141 std::cout << "value @(0.99,0.99,0.01): " << fp3d.value(0.99,0.99,0.01) << std::endl; 142 std::cout << "value @(0.99,0.99,0.21): " << fp3d.value(0.99,0.99,0.21) << std::endl; 143 std::cout << "value @(0.99,0.99,0.41): " << fp3d.value(0.99,0.99,0.41) << std::endl; 144 145 146 std::cout << "original mesh:" << std::endl; 147 showmesh( *uni ); 148 Rappture::Serializer objs; 149 objs.add( uni.pointer() ); 150 Rappture::Ptr<Rappture::SerialBuffer> buffer = objs.serialize(); 151 152 Rappture::Serializer objs2; 153 Rappture::Outcome err = objs2.deserialize(buffer->bytes(), buffer->size()); 154 155 if (err) { 156 err.addContext("while in main program"); 157 std::cout << err.remark() << std::endl; 158 std::cout << err.context() << std::endl; 121 159 exit(1); 122 160 } 161 162 Rappture::Ptr<Rappture::Serializable> uni2ptr = objs2.get(0); 163 Rappture::Ptr<Rappture::Mesh1D> uni2( (Rappture::Mesh1D*)uni2ptr.pointer() ); 164 std::cout << "reconstituted mesh:" << std::endl; 165 showmesh( *uni2 ); 166 123 167 exit(0); 124 168 } -
trunk/src2/core/viz.cc
r364 r370 5 5 #include <string> 6 6 #include "RpFieldRect3D.h" 7 #include "RpFieldPrism3D.h" 7 8 8 9 /* Load a 3D volume from a dx-format file … … 10 11 void 11 12 load_volume_file(int index, char *fname) { 12 int dummy, nx, ny, nz, npts; 13 Rappture::MeshTri2D xymesh; 14 int dummy, nx, ny, nz, nxy, npts; 13 15 double x0, y0, z0, dx, dy, dz, ddx, ddy, ddz; 14 char line[128], *start;16 char line[128], type[128], *start; 15 17 std::ifstream fin(fname); 18 19 int isrect = 1; 16 20 17 21 do { … … 23 27 if (sscanf(start, "object %d class gridpositions counts %d %d %d", &dummy, &nx, &ny, &nz) == 4) { 24 28 // found grid size 29 isrect = 1; 30 } 31 else if (sscanf(start, "object %d class array type float rank 1 shape 3 items %d data follows", &dummy, &nxy) == 2) { 32 std::ofstream ftmp("tmppts"); 33 double xx, yy, zz; 34 isrect = 0; 35 for (int i=0; i < nxy; i++) { 36 fin.getline(line,sizeof(line)-1); 37 if (sscanf(line, "%lg %lg %lg", &xx, &yy, &zz) == 3) { 38 xymesh.addNode( Rappture::Node2D(xx,yy) ); 39 ftmp << xx << " " << yy << std::endl; 40 } 41 } 42 ftmp.close(); 43 44 if (system("voronoi -t < tmppts > tmpcells") == 0) { 45 int cx, cy, cz; 46 std::ifstream ftri("tmpcells"); 47 while (!ftri.eof()) { 48 ftri.getline(line,sizeof(line)-1); 49 if (sscanf(line, "%d %d %d", &cx, &cy, &cz) == 3) { 50 xymesh.addCell(cx, cy, cz); 51 } 52 } 53 ftri.close(); 54 } else { 55 std::cerr << "WARNING: triangularization failed" << std::endl; 56 } 57 } 58 else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) { 59 // found z-grid 25 60 } 26 61 else if (sscanf(start, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) { … … 33 68 else if (ddz != 0.0) { dz = ddz; } 34 69 } 35 else if (sscanf(start, "object %d class array type double rank 0 items %d data follows", &dummy, &npts) == 2) {36 if ( npts != nx*ny*nz) {70 else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) { 71 if (isrect && (npts != nx*ny*nz)) { 37 72 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl; 38 73 return; 39 74 } 75 else if (!isrect && (npts != nxy*nz)) { 76 std::cerr << "inconsistent data: expected " << nxy*nz << " points but found " << npts << " points" << std::endl; 77 return; 78 } 40 79 break; 41 }42 else if (sscanf(start, "object %d class gridconnections", &dummy) == 1) {43 // ignore this44 80 } 45 81 } … … 48 84 // read data points 49 85 if (!fin.eof()) { 50 Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx); 51 Rappture::Mesh1D ygrid(y0, y0+ny*dy, ny); 52 Rappture::Mesh1D zgrid(z0, z0+nz*dz, nz); 53 Rappture::FieldRect3D field(xgrid, ygrid, zgrid); 86 if (isrect) { 87 Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx); 88 Rappture::Mesh1D ygrid(y0, y0+ny*dy, ny); 89 Rappture::Mesh1D zgrid(z0, z0+nz*dz, nz); 90 Rappture::FieldRect3D field(xgrid, ygrid, zgrid); 54 91 55 double dval; 56 int nread = 0; 57 while (!fin.eof()) { 58 if (!(fin >> dval).fail()) { 59 field.define(nread++, dval); 92 double dval; 93 int nread = 0; 94 while (!fin.eof() && nread < npts) { 95 if (!(fin >> dval).fail()) { 96 field.define(nread++, dval); 97 } 60 98 } 61 }62 99 63 // make sure that we read all of the expected points64 if (nread != nx*ny*nz) {65 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << nread << " points" << std::endl;66 return;67 }100 // make sure that we read all of the expected points 101 if (nread != nx*ny*nz) { 102 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << nread << " points" << std::endl; 103 return; 104 } 68 105 69 // figure out a good mesh spacing70 int nsample = 100;71 dx = field.rangeMax(Rappture::xaxis) - field.rangeMin(Rappture::xaxis);72 dy = field.rangeMax(Rappture::yaxis) - field.rangeMin(Rappture::yaxis);73 dz = field.rangeMax(Rappture::zaxis) - field.rangeMin(Rappture::zaxis);74 double dmin = pow((dx*dy*dz)/(nsample*nsample*nsample), 0.333);106 // figure out a good mesh spacing 107 int nsample = 100; 108 dx = field.rangeMax(Rappture::xaxis) - field.rangeMin(Rappture::xaxis); 109 dy = field.rangeMax(Rappture::yaxis) - field.rangeMin(Rappture::yaxis); 110 dz = field.rangeMax(Rappture::zaxis) - field.rangeMin(Rappture::zaxis); 111 double dmin = pow((dx*dy*dz)/(nsample*nsample*nsample), 0.333); 75 112 76 nx = (int)ceil(dx/dmin);77 ny = (int)ceil(dy/dmin);78 nz = (int)ceil(dz/dmin);79 float *data = new float[nx*ny*nz];80 std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl;113 nx = (int)ceil(dx/dmin); 114 ny = (int)ceil(dy/dmin); 115 nz = (int)ceil(dz/dmin); 116 float *data = new float[nx*ny*nz]; 117 std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl; 81 118 82 // generate the uniformly sampled data that we need for a volume 83 int ngen = 0; 84 for (int iz=0; iz < nz; iz++) { 85 double zval = z0 + iz*dmin; 86 for (int iy=0; iy < ny; iy++) { 87 double yval = y0 + iy*dmin; 88 for (int ix=0; ix < nx; ix++) { 89 double xval = x0 + ix*dmin; 90 data[ngen++] = field.value(xval,yval,zval); 119 // generate the uniformly sampled data that we need for a volume 120 int ngen = 0; 121 for (int iz=0; iz < nz; iz++) { 122 double zval = z0 + iz*dmin; 123 for (int iy=0; iy < ny; iy++) { 124 double yval = y0 + iy*dmin; 125 for (int ix=0; ix < nx; ix++) { 126 double xval = x0 + ix*dmin; 127 data[ngen++] = field.value(xval,yval,zval); 128 } 129 } 130 } 131 } else { 132 Rappture::Mesh1D zgrid(z0, z0+nz*dz, nz); 133 Rappture::FieldPrism3D field(xymesh, zgrid); 134 135 double dval; 136 int nread = 0; 137 while (!fin.eof() && nread < npts) { 138 if (!(fin >> dval).fail()) { 139 field.define(nread++, dval); 140 } 141 } 142 143 // make sure that we read all of the expected points 144 if (nread != nxy*nz) { 145 std::cerr << "inconsistent data: expected " << nxy*nz << " points but found " << nread << " points" << std::endl; 146 return; 147 } 148 149 // figure out a good mesh spacing 150 int nsample = 100; 151 dx = field.rangeMax(Rappture::xaxis) - field.rangeMin(Rappture::xaxis); 152 dy = field.rangeMax(Rappture::yaxis) - field.rangeMin(Rappture::yaxis); 153 dz = field.rangeMax(Rappture::zaxis) - field.rangeMin(Rappture::zaxis); 154 double dmin = pow((dx*dy*dz)/(nsample*nsample*nsample), 0.333); 155 156 nx = (int)ceil(dx/dmin); 157 ny = (int)ceil(dy/dmin); 158 nz = (int)ceil(dz/dmin); 159 float *data = new float[nx*ny*nz]; 160 std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl; 161 162 // generate the uniformly sampled data that we need for a volume 163 int ngen = 0; 164 for (int iz=0; iz < nz; iz++) { 165 double zval = z0 + iz*dmin; 166 for (int iy=0; iy < ny; iy++) { 167 double yval = y0 + iy*dmin; 168 for (int ix=0; ix < nx; ix++) { 169 double xval = x0 + ix*dmin; 170 data[ngen++] = field.value(xval,yval,zval); 171 } 91 172 } 92 173 }
Note: See TracChangeset
for help on using the changeset viewer.