Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] Re: [SCIRUN-CVS] r34247 - trunk/src/Core/Containers


Chronological Thread 
  • From: Aaron Knoll <knolla@cs.utah.edu>
  • To: James Bigler <bigler@sci.utah.edu>
  • Cc: manta@sci.utah.edu
  • Subject: [MANTA] Re: [SCIRUN-CVS] r34247 - trunk/src/Core/Containers
  • Date: Tue, 16 May 2006 17:17:42 -0600

OK, fair enough. I ended up putting that in DIRT because all Array3 callers used it, but I can write a separate function :)

-Aaron

On May 16, 2006, at 5:14 PM, James Bigler wrote:

Is there a reason lookup_safe can't be done outside of the class? I'm quite hesitant to have code that arbitrarily returns zero from a lookup function.

Thanks,
James

knolla@sci.utah.edu wrote:
Author: knolla
Date: Tue May 16 17:05:41 2006
New Revision: 34247
Modified:
   trunk/src/Core/Containers/Array3.h
Log:
added a safe lookup to Array3.h
Modified: trunk/src/Core/Containers/Array3.h
===================================================================== =========
--- trunk/src/Core/Containers/Array3.h  (original)
+++ trunk/src/Core/Containers/Array3.h  Tue May 16 17:05:41 2006
@@ -55,6 +55,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <SCIRun/Core/Util/Assert.h>
  #ifndef SCI_NOPERSISTENT
 #include <Core/Persistent/Persistent.h>
@@ -68,7 +69,7 @@
 template<class T> class Array3;
 #ifndef SCI_NOPERSISTENT
 template<class T> void Pio(Piostream& stream, Array3<T>& array);
-template<class T> void Pio(Piostream& stream, Array3<T>& array, const string&);
+template<class T> void Pio(Piostream& stream, Array3<T>& array, const std::string&);
 template<class T> void Pio(Piostream& stream, Array3<T>*& array);
 #endif // #ifndef SCI_NOPERSISTENT
 @@ -134,6 +135,15 @@
     ASSERTL3(d3>=0 && d3<dm3);
     return objs[d1][d2][d3];
   }
+ + //lookup returning 0 if out of bounds. Only works for scalar datatypes.
+  inline T lookup_safe(int d1, int d2, int d3) const
+  {
+    if (d1>=0 && d1<dm1 && d2>=0 && d2<dm2 && d3>=0 && d3<dm3)
+      return objs[d1][d2][d3];
+    else
+      return 0;
+  }
        //////////
   //Array2 Copy Method
@@ -148,6 +158,8 @@
   //////////
   //Returns the number of spaces in dim3
   inline int dim3() const {return dm3;}
+ + inline long get_datasize() const { return dm1*dm2*dm3*long (sizeof(T)); }
        //////////
   //Re-size the Array
@@ -164,8 +176,8 @@
    //////////
   //read/write from a separate raw file
-  int input( const string& );
-  int output( const string&);
+  int input( const std::string& );
+  int output( const std::string&);
  #ifndef SCI_NOPERSISTENT
 #if defined(_AIX)
@@ -173,13 +185,13 @@
friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array3<type>&);
   template <typename type>
friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array3<type>&,
-                                            const string &);
+                                            const std::string &);
   template <typename type>
friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array3<type>*&);
 #else
friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array3<T>&);
friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array3<T>&, - const string &);
+                                            const std::string &);
friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array3<T>*&);
 #endif
 #endif // #ifndef SCI_NOPERSISTENT
@@ -340,7 +352,7 @@
  template<class T>
void Pio(Piostream& stream, Array3<T>& data, - const string& filename)
+         const std::string& filename)
 {
 #ifdef __GNUG__
 #else
@@ -368,7 +380,7 @@
  template<class T>
 int
-Array3<T>::input( const string &filename ) +Array3<T>::input ( const std::string &filename ) {
   std::cerr << "Array3: Split input\n";
 @@ -402,7 +414,7 @@
  template<class T>
 int
-Array3<T>::output( const string &filename ) +Array3<T>::output ( const std::string &filename ) {
   std::cerr << "Array3 output to " << filename << std::endl;
   // get raw data





  • [MANTA] Re: [SCIRUN-CVS] r34247 - trunk/src/Core/Containers, Aaron Knoll, 05/16/2006

Archive powered by MHonArc 2.6.16.

Top of page