[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd/cvd image.h [subimage2]
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd/cvd image.h [subimage2] |
Date: |
Fri, 30 Jun 2006 23:26:22 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Branch: subimage2
Changes by: Edward Rosten <edrosten> 06/06/30 23:26:22
Modified files:
cvd : image.h
Log message:
A number of convenience constructors added:
Image<T>(ImageRef,T) to create an image already filled
Image<T>(make_pair(ImageRef, T) as above, but a single value is
used.
Allows containers of ready-make
images
to
be instantiated.
Image<T>(otherimage.copy_from_me()) Allows containers to be easily
created
where each element is a duplicate
of
some image, not just a reference to it.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/image.h?cvsroot=libcvd&only_with_tag=subimage2&r1=1.20.2.9&r2=1.20.2.10
Patches:
Index: image.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/image.h,v
retrieving revision 1.20.2.9
retrieving revision 1.20.2.10
diff -u -b -r1.20.2.9 -r1.20.2.10
--- image.h 30 Jun 2006 00:43:48 -0000 1.20.2.9
+++ image.h 30 Jun 2006 23:26:22 -0000 1.20.2.10
@@ -37,6 +37,7 @@
#include <cvd/image_ref.h>
#include <cvd/exceptions.h>
#include <string>
+#include <utility>
#include <iterator>
#include <cvd/internal/aligned_mem.h>
@@ -528,7 +529,19 @@
template<class T>
class Image: public BasicImage<T>
{
+ private:
+ struct CopyPlaceHolder
+ {
+ const Image* im;
+ };
+
public:
+ static std::pair<ImageRef, T> CreateNew(const ImageRef& i,
const T& v)
+ {
+ return make_pair(i, v);
+ }
+
+
///Copy constructor. This does not copy the data, it just
creates a new
///reference to the image data
///@param copy The image to copy
@@ -539,6 +552,35 @@
}
+ /**CopyFrom" constructor. If constructed from this, it creates
+ a new copy of the data. This can only be used in conjunction
with
+ This can be used in conjunction with containers. The
following code
+ @code
+ Image<float> blank(ImageRef(100,100));
+ blank.fill(0);
+
+ vector<Image<float> > images(10, blank.copy_from_me());
+ @endcode
+ Creates 10 blank images. Without the the @ref copy_from_me,
all the images
+ would refer to the same data.
+
+ @ref copy_from_me
+ @param c The (placeholder) image to copy from.
+ **/
+ Image(const CopyPlaceHolder& c)
+ {
+ dup_from(c.im);
+ }
+
+ ///This returns a place holder from which an image can be
constructed.
+ ///On construction, a new copy of the data is made.
+ CopyPlaceHolder copy_from_me()
+ {
+ CopyPlaceHolder c = {this};
+ return c;
+ }
+
+
///Make a (new) copy of the image, also making a copy of the
data
///@param copy The image to copy
void copy_from(const BasicImage<T>& copy)
@@ -549,6 +591,10 @@
std::copy(copy.begin(), copy.end(), this->begin());
}
+
+
+
+
///Make a (new) copy of the image, also making a copy of the
data
///@param copy The image to copy
void copy_from(const SubImage<T>& copy)
@@ -597,6 +643,33 @@
this->my_data =
Internal::aligned_mem<T,16>::alloc(this->totalsize());
}
+ ///Create a filled image of a given size
+ ///@param size The size of image to create
+ ///@param val The value to fill the image with
+ Image(const ImageRef& size, const T& val)
+ {
+ Image<T> tmp(size);
+ tmp.fill(val);
+ dup_from(&tmp);
+ }
+
+
+ ///Create a filled image of a given size
+ ///This function allows a filled image to be constructed from a
single value.
+ ///This is useful for the following code:
+ /// @code
+ /// vector<Image<byte> > images(10,
Image<byte>::CreateNew(ImageRef(100,100), 255));
+ /// @endcode
+ /// See also @ref CreateNew, which is a synonym for make_pair
+ ///@param im The size and fill for the image to be created
+ Image(const std::pair<ImageRef, T>& im)
+ {
+ Image<T> tmp(im.first);
+ tmp.fill(im.second);
+ dup_from(&tmp);
+ }
+
+
///Resize the image (destroying the data). The image is resized
even if the new size is the same as the old one.
///@param size The new size of the image
void resize(const ImageRef& size)
@@ -613,6 +686,8 @@
private:
+
+
int* num_copies; //Reference count.
inline void remove() //Get rid of a reference to the
data
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/28
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/29
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/29
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/29
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/29
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/29
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/29
- [libcvd-members] libcvd/cvd image.h [subimage2],
Edward Rosten <=
- [libcvd-members] libcvd/cvd image.h [subimage2], Edward Rosten, 2006/06/30