libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd cvd/internal/io/text.h pnm_src/text.cxx ...


From: Edward Rosten
Subject: [libcvd-members] libcvd cvd/internal/io/text.h pnm_src/text.cxx ...
Date: Mon, 26 Jan 2009 15:16:43 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        09/01/26 15:16:43

Added files:
        cvd/internal/io: text.h 
        pnm_src        : text.cxx text_write.cc 

Log message:
        Added missing files.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/io/text.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/text.cxx?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/text_write.cc?cvsroot=libcvd&rev=1.1

Patches:
Index: cvd/internal/io/text.h
===================================================================
RCS file: cvd/internal/io/text.h
diff -N cvd/internal/io/text.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ cvd/internal/io/text.h      26 Jan 2009 15:16:41 -0000      1.1
@@ -0,0 +1,87 @@
+/*                       
+       This file is part of the CVD Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef CVD_INCLUDE_INTERNAL_IO_TEXT_H
+#define CVD_INCLUDE_INTERNAL_IO_TEXT_H
+
+#include <iostream>
+#include <memory>
+#include <vector>
+#include <string>
+#include <cvd/image.h>
+#include <cvd/internal/load_and_save.h>
+
+namespace CVD
+{
+namespace TEXT
+{
+
+       using CVD::Internal::TypeList;
+       using CVD::Internal::Head;
+
+       class ReadPimpl;
+       class reader
+       {
+               public:
+                       reader(std::istream&);
+                       ~reader();
+
+                       ImageRef size();
+
+                       void get_raw_pixel_line(double*);
+
+                       std::string datatype();
+                       std::string name();
+
+
+                       typedef TypeList<double,  Head> Types;
+               
+               private:
+                       std::auto_ptr<ReadPimpl> t; 
+       };
+
+
+       
////////////////////////////////////////////////////////////////////////////////
+       //
+       // TEXT writing
+       //
+       class WritePimpl;
+
+       class writer
+       {
+               public:
+                       writer(std::ostream&, ImageRef size, const std::string& 
type);
+                       ~writer();
+
+                       void write_raw_pixel_line(const double*);
+                       void write_raw_pixel_line(const float*);
+
+                       template<class Incoming> struct Outgoing
+                       {               
+                               typedef double type;
+                       };              
+
+               private:
+                       std::auto_ptr<WritePimpl> t; 
+       };
+       
+}
+}
+#endif

Index: pnm_src/text.cxx
===================================================================
RCS file: pnm_src/text.cxx
diff -N pnm_src/text.cxx
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pnm_src/text.cxx    26 Jan 2009 15:16:42 -0000      1.1
@@ -0,0 +1,149 @@
+/*                       
+       This file is part of the CVD Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include "cvd/image_io.h"
+#include "cvd/config.h"
+#include <iterator>
+#include <vector>
+#include <sstream>
+#include <iostream>
+
+using namespace CVD;
+using namespace CVD::TEXT;
+using namespace CVD::Exceptions::Image_IO;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Private implementation of TIFF reading
+//
+
+class CVD::TEXT::ReadPimpl
+{
+       public:
+               ReadPimpl(istream&);
+               ~ReadPimpl();
+               ImageRef size();
+               string datatype();
+               void get_raw_pixel_line(double* data);
+
+       private:
+               istream& i;
+               unsigned long row;
+               ImageRef my_size;
+
+               vector<vector<double> > raster_data;
+};
+
+
+void ReadPimpl::get_raw_pixel_line(double* d)
+{
+       if(row  > (unsigned long)my_size.y)
+               throw InternalLibraryError("CVD", "Read past end of image.");
+       
+       copy(raster_data[row].begin(), raster_data[row].end(), d);
+       row ++;
+}
+
+string ReadPimpl::datatype()
+{
+       return "double";
+}
+
+ImageRef ReadPimpl::size()
+{
+       return my_size;
+}
+
+ReadPimpl::~ReadPimpl()
+{      
+}
+
+
+ReadPimpl::ReadPimpl(istream& is)
+:i(is),row(0)
+{
+       my_size.x = -1;
+       my_size.y = 0;
+
+       string line;
+       raster_data.reserve(8192);
+
+       for(;;)
+       {
+               getline(i, line);
+
+               if(i.fail())
+                       break;
+               
+               istringstream l(line);
+               raster_data.resize(my_size.y + 1);
+               copy(istream_iterator<double>(l), istream_iterator<double>(), 
back_inserter(raster_data.back()));
+
+               if(raster_data.back().size() == 0)
+                       break;
+               
+               if(my_size.y == 0)
+                       my_size.x = raster_data[0].size();
+               else if(my_size.x != (int)raster_data.back().size())
+               {
+                       ostringstream err;
+                       err << "All rows must have the same number of columns: 
bad row is " 
+                               << my_size.y;
+                       throw MalformedImage(err.str());
+               }
+
+               my_size.y++;
+       }
+}
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Implementation of public parts of text reading
+//
+
+reader::reader(istream& i)
+:t(new ReadPimpl(i))
+{}
+
+reader::~reader()
+{
+}
+
+string reader::datatype()
+{
+       return t->datatype();
+}
+
+string reader::name()
+{
+       return "TEXT";
+}
+
+ImageRef reader::size()
+{
+       return t->size();
+};
+
+//Mechanically generate the pixel reading calls.
+void reader::get_raw_pixel_line(double*d){t->get_raw_pixel_line(d);}

Index: pnm_src/text_write.cc
===================================================================
RCS file: pnm_src/text_write.cc
diff -N pnm_src/text_write.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pnm_src/text_write.cc       26 Jan 2009 15:16:43 -0000      1.1
@@ -0,0 +1,119 @@
+/*                       
+       This file is part of the CVD Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include "cvd/internal/io/text.h"
+#include "cvd/image_io.h"
+#include <algorithm>
+#include <iostream>
+#include <iterator>
+#include <iomanip>
+
+using namespace CVD;
+using namespace CVD::TEXT;
+using namespace CVD::Exceptions::Image_IO;
+using namespace std;
+
+class CVD::TEXT::WritePimpl
+{
+       public:
+               WritePimpl(ostream&oo, ImageRef size, const string& t)
+               :o(oo),my_size(size),type(t),row(0)
+               {
+                       if(t != "double" && t != "float")
+                               throw UnsupportedImageSubType("TEXT", t);
+               }
+
+               ~WritePimpl()
+               {
+               }
+
+               void write_raw_pixel_line(const double* d)
+               {
+                       if(type != "double")
+                               throw WriteTypeMismatch(type, "double");
+
+                       //Do some sanity checking
+                       if(row >= (unsigned long)my_size.y)
+                               throw InternalLibraryError("CVD", "Write past 
end of image.");
+                       o <<scientific << setw(24) << setprecision(16);
+
+                       copy(d, d + my_size.x-1, ostream_iterator<double>(o, " 
"));
+                       o << d[my_size.x-1] << endl;
+                       row++;
+               }
+
+               void write_raw_pixel_line(const float* d)
+               {
+                       if(type != "float")
+                               throw WriteTypeMismatch(type, "float");
+
+                       //Do some sanity checking
+                       if(row >= (unsigned long)my_size.y)
+                               throw InternalLibraryError("CVD", "Write past 
end of image.");
+                       o <<scientific << setw(15) << setprecision(8);
+
+                       copy(d, d + my_size.x-1, ostream_iterator<float>(o, " 
"));
+                       o << d[my_size.x-1] << endl;
+                       row++;
+               }
+
+       private:
+               ostream& o;
+               ImageRef my_size;
+               string   type;
+               unsigned long row;
+};
+
+TEXT::writer::writer(ostream& o, ImageRef size, const string& type)
+:t(new WritePimpl(o, size, type))
+{}
+
+TEXT::writer::~writer()
+{}
+
+void TEXT::writer::write_raw_pixel_line(const double* d)
+{
+       t->write_raw_pixel_line(d);
+}
+
+
+void TEXT::writer::write_raw_pixel_line(const float* d)
+{
+       t->write_raw_pixel_line(d);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]