arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

nrroUtil.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// nrroUtil.cpp
00019 
00020 #include "nrro.h"
00021 #include "nrroUtil.h"
00022 #include "nrroDispatch.h"
00023 #include <iostream>
00024 
00025 using namespace std;
00026 using namespace gutz;
00027 
00028 NrroSP reshapeNrroImageA(const NrroSP nin,
00029                          const vec2i size,    /// size of image you want back
00030                          const vec2f minPos,  /// [0-1] min pos, relative to greatest axis
00031                          const vec2f maxPos,  /// [0-1] max pos, relative to greatest axis
00032                          const NrroKernel &k)
00033 {
00034    if(nin.isNull())
00035    {
00036       cerr << "reshapeNrroImage(), nrro is null!!!" << endl;
00037       return NrroSP();
00038    }
00039    if(!(nin->getKind() & Nrro::IMAGE))
00040    {
00041       cerr << "reshapeNrroImage(), nrro not an image !!!" << endl;
00042       return NrroSP();
00043    }
00044 
00045    NrroSP n = new Nrro(*nin);
00046 
00047    /// gota be reasonable here....
00048    n->forceMultiChannel();
00049 
00050    /// inverse Aspect ratio of image,
00051    /// remember that 1 is the relative size of 
00052    /// the largest spatial axis.
00053    vec2f invAspect(vec2f_one);
00054 
00055    /// x > y 
00056    if( n->axisSize(1) > n->axisSize(2) )
00057    {
00058       invAspect.y = n->axisSize(1)/ n->axisSize(2);
00059    }
00060    else /// y > x
00061    {
00062       invAspect.x = n->axisSize(2)/ n->axisSize(1);
00063    }
00064 
00065    /// crop and padd the image to the right size, relatively speaking
00066    int cpmin[3] = {0,
00067                    int(minPos.x * invAspect.x * (n->dim(1)-1)), 
00068                    int(minPos.y * invAspect.y * (n->dim(2)-1))};
00069    
00070    int cpmax[3] = {int(n->dim(0)) - 1 ,
00071                    int(maxPos.x * invAspect.x * (n->dim(1)-1)) + 1, 
00072                    int(maxPos.y * invAspect.y * (n->dim(2)-1)) + 1};
00073 
00074    n = n->cropPad(cpmin, cpmax);
00075 
00076 
00077    /// resample to the actual right size
00078    int rdims[3] = {-1, size.x, size.y};
00079    n = n->resample(rdims, k);
00080 
00081    n->setKind(Nrro::IMAGE);
00082 
00083    return n;
00084 }
00085 
00086 

Send questions, comments, and bug reports to:
jmk