Exemplo n.º 1
0
int main(int ac, char **av){
  long double x,SUM = 0.0;
  struct timeval s,t;
  double startTime, endTime;

  if(ac != 2){
    printf("引数は分割するぶんの数を指定して下さい。\n");
    exit(1);
  }

  int N = atoi(av[1]);
  
  gettimeofday(&s, NULL);//----------------時間計測開始
  for(int i=0; i<N; i++){
    //x = i*1.0L/N;
    //SUM += F(x);
    SUM += quadrature((long double)N, (long double)i);
  }
    
  SUM = 4.0L * SUM;

  gettimeofday(&t, NULL);//--------------------時間計測終了
  startTime = s.tv_sec + (double)(s.tv_usec * 1e-6);
  endTime = t.tv_sec + (double)(t.tv_usec * 1e-6);
  
  //printf("%f ms\t PI = %.30Lf\n",(endTime - startTime) * 1000,SUM);
  printf("%d %f %.30Lf\n", N/1000000, (endTime - startTime) * 1000, SUM);
  return 0;
}
int main(int narg, char* argc[])
{
    std::cout.setf( std::ios::fixed, std:: ios::floatfield );
    std::cout.precision(8);
    
    double infIntegral, supIntegral, midIntegral;
    
    timestamp_t inicio, fim;
	inicio = get_timestamp();
	
		std::vector<Function*> functions;
	
		functions.push_back( new Function1() );
		functions.push_back( new Function2() );

		GaussianQuadrature quadrature(argc[1], functions);
		midIntegral = quadrature.calculateIntegral();

		std::cout << "Quad: " << midIntegral << '\n';

		ClosedNewtonCotes infTrapezio(argc[2], 1);
		infIntegral = infTrapezio.calculateIntegral();
	
		std::cout << "Inf: " << infIntegral << '\n';
	
		ClosedNewtonCotes supTrapezio(argc[3], 1);
		supIntegral = supTrapezio.calculateIntegral();

		std::cout << "Sup: " << supIntegral << '\n';
	
		std::cout << "Integral: " << infIntegral + midIntegral + supIntegral << "\n";

    fim = get_timestamp();	
	
	std::cout << "tempo: " << (fim - inicio)/1000.0L << " milissegundos.\n";

	return 0;
}
int main(int narg, char* argc[])
{
    std::cout.setf( std::ios::fixed, std:: ios::floatfield );
    std::cout.precision(8);
    
    timestamp_t inicio, fim;
	inicio = get_timestamp();
	
		std::vector<Function*> functions;
	
		functions.push_back( new Function1() );
		functions.push_back( new Function2() );

		GaussianQuadrature quadrature(argc[1], functions);

		std::cout << "Integral: " << quadrature.calculateIntegral() << "\n";

    fim = get_timestamp();	
	
	std::cout << "tempo: " << (fim - inicio)/1000.0L << " milissegundos.\n";

	return 0;
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
int main( int argc, char * argv[] )
{
    //--------------------------------------------------------------------------
    const unsigned    geomDeg   = 1;
    const unsigned    dim       = 2;
    // degrees of lowest-order TH element
    const unsigned    fieldDegU = 2; 
    const unsigned    fieldDegP = 1;

    const unsigned    tiOrder   = 1;
    typedef  base::time::BDF<tiOrder> MSM;
    
    const base::Shape shape     = base::SimplexShape<dim>::value;
    const base::Shape surfShape = base::SimplexShape<dim-1>::value;

    //--------------------------------------------------------------------------
    if ( argc != 2 ) {
        std::cout << "Usage:  " << argv[0] << " input.dat \n\n";
        return -1;
    }

    const std::string inputFile = boost::lexical_cast<std::string>( argv[1] );

    //--------------------------------------------------------------------------
    std::string meshFile, surfFile;
    double viscosity, density, tolerance, penaltyFactor, stepSize;
    unsigned maxIter, numSteps;
    {    
        //Feed properties parser with the variables to be read
        base::io::PropertiesParser prop;
        prop.registerPropertiesVar( "meshFile",         meshFile );
        prop.registerPropertiesVar( "surfFile",         surfFile );
        prop.registerPropertiesVar( "viscosity",        viscosity );
        prop.registerPropertiesVar( "density",          density );
        prop.registerPropertiesVar( "maxIter",          maxIter );
        prop.registerPropertiesVar( "tolerance",        tolerance );
        prop.registerPropertiesVar( "penaltyFactor",    penaltyFactor );
        prop.registerPropertiesVar( "stepSize",         stepSize );
        prop.registerPropertiesVar( "numSteps",         numSteps );

        // Read variables from the input file
        std::ifstream inp( inputFile.c_str()  );
        VERIFY_MSG( inp.is_open(), "Cannot open input file" );
        prop.readValues( inp );
        inp.close( );

        // Make sure all variables have been found
        if ( not prop.isEverythingRead() ) {
            prop.writeUnread( std::cerr );
            VERIFY_MSG( false, "Could not find above variables" );
        }
    }

    const std::string baseName = base::io::baseName( meshFile, ".smf" );

    //--------------------------------------------------------------------------
    typedef base::Unstructured<shape,geomDeg>     Mesh;

    Mesh mesh;
    {
        std::ifstream smf( meshFile.c_str() );
        VERIFY_MSG( smf.is_open(), "Cannot open mesh file" );
        base::io::smf::readMesh( smf, mesh );
        smf.close();
    }

    //--------------------------------------------------------------------------
    // Surface mesh
    typedef base::Unstructured<surfShape,1,dim>    SurfMesh;

    SurfMesh surfMesh;
    {
        std::ifstream smf( surfFile.c_str() );
        base::io::smf::readMesh( smf, surfMesh );
        smf.close();
    }

    //--------------------------------------------------------------------------
    // Compute the level set data
    typedef base::cut::LevelSet<dim> LevelSet;
    std::vector<LevelSet> levelSet;
    const bool isSigned = true;
    base::cut::bruteForce( mesh, surfMesh, isSigned, levelSet );

    const unsigned kernelDegEstimate = 5;

    //--------------------------------------------------------------------------
    // Make cut cell structure
    typedef base::cut::Cell<shape> Cell;
    std::vector<Cell> cells;
    base::cut::generateCutCells( mesh, levelSet, cells );

    // Quadrature 
    typedef base::cut::Quadrature<kernelDegEstimate,shape> CutQuadrature;
    CutQuadrature quadrature( cells, true );

    // for surface
    typedef base::SurfaceQuadrature<kernelDegEstimate,shape> SurfaceQuadrature;
    SurfaceQuadrature surfaceQuadrature;

    //------------------------------------------------------------------------------
    // Finite element bases
    const unsigned    nHist = MSM::numSteps;
    
    const unsigned    doFSizeU = dim;
    typedef base::fe::Basis<shape,fieldDegU>                FEBasisU;
    typedef base::cut::ScaledField<FEBasisU,doFSizeU,nHist> Velocity;
    Velocity velocity;
    base::dof::generate<FEBasisU>( mesh, velocity );
    
    const unsigned    doFSizeP = 1;
    typedef base::fe::Basis<shape,fieldDegP>                FEBasisP;
    typedef base::cut::ScaledField<FEBasisP,doFSizeP,nHist> Pressure;
    Pressure pressure;
    base::dof::generate<FEBasisP>( mesh, pressure );

    const unsigned    doFSizeS = dim;
    typedef base::fe::Basis<surfShape,1>              FEBasisS;
    typedef base::Field<FEBasisS,doFSizeS>            SurfField;
    SurfField surfVelocity, surfForces;
    base::dof::generate<FEBasisS>( surfMesh, surfVelocity );
    base::dof::generate<FEBasisS>( surfMesh, surfForces   );

    // set initial condition to the identity 
    base::dof::setField( surfMesh, surfVelocity,
                         boost::bind( &surfaceVelocity<dim,
                                      SurfField::DegreeOfFreedom>, _1, _2 ) );


    // boundary datum    
    base::cut::TransferSurfaceDatum<SurfMesh,SurfField,Mesh::Element>
        s2d( surfMesh, surfVelocity, levelSet );
    
    //--------------------------------------------------------------------------
    //  surface mesh
    typedef base::mesh::BoundaryMeshBinder<Mesh>::Type BoundaryMesh;
    BoundaryMesh boundaryMesh, immersedMesh;

    // from boundary
    {
        // identify list of element boundary faces
        base::mesh::MeshBoundary meshBoundary;
        meshBoundary.create( mesh.elementsBegin(), mesh.elementsEnd() );

        // generate a mesh from that list (with a filter)
        base::mesh::generateBoundaryMesh( meshBoundary.begin(),
                                          meshBoundary.end(),
                                          mesh, boundaryMesh,
                                          boost::bind( &boundaryFilter<dim>, _1 ) );

        // make a surface mesh from the implicit surface
        base::cut::generateSurfaceMesh<Mesh,Cell>( mesh, cells, immersedMesh );
    }

    // the composite field with geometry, velocity and pressure
    typedef base::asmb::FieldBinder<Mesh,Velocity,Pressure> Field;
    Field field( mesh, velocity, pressure );

    // define the system blocks (U,U), (U,P), and (P,U)
    typedef Field::TupleBinder<1,1,1>::Type TopLeft;
    typedef Field::TupleBinder<1,2>::Type   TopRight;
    typedef Field::TupleBinder<2,1>::Type   BotLeft;


    std::vector<double> supportsU, supportsP;
    std::size_t numDoFsU = std::distance( velocity.doFsBegin(), velocity.doFsEnd() );
    supportsU.resize( numDoFsU );
    std::size_t numDoFsP = std::distance( pressure.doFsBegin(), pressure.doFsEnd() );
    supportsP.resize( numDoFsP );

    base::cut::supportComputation( mesh, velocity, quadrature, supportsU );
    base::cut::supportComputation( mesh, pressure, quadrature, supportsP );

    velocity.scaleAndTagBasis( supportsU, 1.e-8 );
    pressure.scaleAndTagBasis( supportsP, 1.e-8 ); 
    //velocity.tagBasis( supportsU, 1.e-8 );
    //pressure.tagBasis( supportsP, 1.e-8 ); 

    // Fix one pressure dof
    // Pressure::DoFPtrIter pIter = pressure.doFsBegin();
    // std::advance( pIter, std::distance( pressure.doFsBegin(), pressure.doFsEnd() )/5 );
    // (*pIter) -> constrainValue( 0, 0.0 );

    // Number of DoFs after constraint application!
    numDoFsU =
        base::dof::numberDoFsConsecutively( velocity.doFsBegin(), velocity.doFsEnd() );
    std::cout << "# Number of velocity dofs " << numDoFsU << std::endl;

    numDoFsP =
        base::dof::numberDoFsConsecutively( pressure.doFsBegin(), pressure.doFsEnd(),
            numDoFsU );
    std::cout << "# Number of pressure dofs " << numDoFsP << std::endl;

    // kernels
    typedef fluid::StressDivergence<  TopLeft::Tuple>  StressDivergence;
    typedef fluid::Convection<        TopLeft::Tuple>  Convection;
    typedef fluid::PressureGradient<  TopRight::Tuple> GradP;
    typedef fluid::VelocityDivergence<BotLeft::Tuple>  DivU;

    StressDivergence stressDivergence( viscosity );
    Convection       convection(       density );
    GradP            gradP;
    DivU             divU( true );

    // for surface fields
    typedef base::asmb::SurfaceFieldBinder<BoundaryMesh,Velocity,Pressure> SurfaceFieldBinder;
    typedef SurfaceFieldBinder::TupleBinder<1,1,1>::Type STBUU;
    typedef SurfaceFieldBinder::TupleBinder<1,2  >::Type STBUP;
    SurfaceFieldBinder   boundaryFieldBinder(  boundaryMesh, velocity, pressure );
    SurfaceFieldBinder   immersedFieldBinder(  immersedMesh, velocity, pressure );

    std::ofstream forces( "forces.dat" );

    for ( unsigned step = 0; step < numSteps; step++ ) {

        const double time = step * stepSize;
        const double factor = ( time < 1.0 ? time : 1.0 );
    
        std::cout << step << ":  time=" << time << ", factor=" << factor
                  << "\n";

        //base::dof::clearDoFs( velocity );
        //base::dof::clearDoFs( pressure );
        
        //--------------------------------------------------------------------------
        // Nonlinear iterations
        unsigned iter = 0;
        while( iter < maxIter ) {

            // Create a solver object
            typedef base::solver::Eigen3           Solver;
            Solver solver( numDoFsU + numDoFsP );

            std::cout << "* Iteration " << iter << std::flush;

            // compute inertia terms, d/dt, due to time integration
            base::time::computeInertiaTerms<TopLeft,MSM>( quadrature, solver,
                                                          field, stepSize, step,
                                                          density );
    
            // Compute system matrix
            base::asmb::stiffnessMatrixComputation<TopLeft>( quadrature, solver,
                                                             field, stressDivergence );

            base::asmb::stiffnessMatrixComputation<TopLeft>( quadrature, solver,
                                                             field, convection );

            base::asmb::stiffnessMatrixComputation<TopRight>( quadrature, solver,
                                                              field, gradP );

            base::asmb::stiffnessMatrixComputation<BotLeft>( quadrature, solver,
                                                             field, divU );
            // compute residual forces
            base::asmb::computeResidualForces<TopLeft >( quadrature, solver, field,
                                                         stressDivergence );
            base::asmb::computeResidualForces<TopLeft >( quadrature, solver, field, convection );
            base::asmb::computeResidualForces<TopRight>( quadrature, solver, field, gradP );
            base::asmb::computeResidualForces<BotLeft >( quadrature, solver, field, divU );
        
            // Parameter classes
            base::nitsche::OuterBoundary ob( viscosity );
            base::nitsche::ImmersedBoundary<Cell> ib( viscosity, cells );

            // Penalty method
            base::nitsche::penaltyLHS<STBUU>( surfaceQuadrature, solver,
                                              boundaryFieldBinder, ob, penaltyFactor );
        
            base::nitsche::penaltyRHS<STBUU>( surfaceQuadrature, solver, boundaryFieldBinder, 
                                              boost::bind( &dirichlet<dim>, _1, factor),
                                              ob, penaltyFactor );

            base::nitsche::penaltyLHS<STBUU>( surfaceQuadrature, solver,
                                              immersedFieldBinder, ib, penaltyFactor );
        
            base::nitsche::penaltyRHS2<STBUU>( surfaceQuadrature, solver, immersedFieldBinder,
                                               s2d, ib, penaltyFactor );

            // Nitsche terms
            base::nitsche::primalEnergyLHS<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                                   boundaryFieldBinder, ob );
            base::nitsche::dualEnergyLHS<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                                 boundaryFieldBinder, ob );
            base::nitsche::energyRHS<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                             boundaryFieldBinder,
                                             boost::bind( &dirichlet<dim>, _1, factor),
                                             ob );
        
            base::nitsche::primalEnergyLHS<STBUP>( gradP, surfaceQuadrature, solver,
                                                   boundaryFieldBinder, ob );
            base::nitsche::dualEnergyLHS<STBUP>( gradP, surfaceQuadrature, solver,
                                                 boundaryFieldBinder, ob );
         
            base::nitsche::energyRHS<STBUP>( gradP, surfaceQuadrature, solver,
                                             boundaryFieldBinder,
                                             boost::bind( &dirichlet<dim>, _1, factor), ob );

            base::nitsche::energyResidual<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                                  boundaryFieldBinder, ob );
            
            base::nitsche::energyResidual<STBUP>( gradP, surfaceQuadrature, solver,
                                                  boundaryFieldBinder, ob );

            base::nitsche::primalEnergyLHS<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                                   immersedFieldBinder, ib );
            base::nitsche::dualEnergyLHS<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                                 immersedFieldBinder, ib );

            base::nitsche::energyRHS2<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                              immersedFieldBinder, s2d, ib );
            
            base::nitsche::primalEnergyLHS<STBUP>( gradP, surfaceQuadrature, solver,
                                                   immersedFieldBinder, ib );
            base::nitsche::dualEnergyLHS<STBUP>( gradP, surfaceQuadrature, solver,
                                                 immersedFieldBinder, ib );

            base::nitsche::energyRHS2<STBUP>( gradP, surfaceQuadrature, solver,
                                              immersedFieldBinder, s2d, ib );

            base::nitsche::energyResidual<STBUU>( stressDivergence, surfaceQuadrature, solver,
                                                  immersedFieldBinder, ib );

            base::nitsche::energyResidual<STBUP>( gradP, surfaceQuadrature, solver,
                                                  immersedFieldBinder, ib );
        
            // Finalise assembly
            solver.finishAssembly();

            // check convergence via solver norms
            const double residualNorm = solver.norm();
            std::cout << " |R| = " << residualNorm << std::flush;

            if ( residualNorm < tolerance * viscosity) {
                std::cout << std::endl;
                break;
            }

            // Solve
            solver.superLUSolve();

            // distribute results back to dofs
            base::dof::addToDoFsFromSolver( solver, velocity );
            base::dof::addToDoFsFromSolver( solver, pressure );
            //base::dof::setDoFsFromSolver( solver, pressure );
        
            // check convergence via solver norms
            const double incrementNorm = solver.norm(0, numDoFsU );
            std::cout << " |dU| = " << incrementNorm << std::endl;

            // push history
            base::dof::pushHistory( velocity );
            base::dof::pushHistory( pressure );
        
            if ( incrementNorm < tolerance ) break;

            iter++;

        }

        writeVTKFile( baseName, step, mesh, velocity, pressure, levelSet, viscosity );
        {
            base::Vector<dim>::Type sumOfForces = base::constantVector<dim>( 0. );
            
            typedef Field::TupleBinder<1,2>::Type UP;
            //typedef fluid::Stress<UP::Tuple> Stress;
            //Stress stress( viscosity );
            typedef fluid::Traction<UP::Tuple> Traction;
            Traction traction( viscosity );
                
            base::cut::ComputeSurfaceForces<SurfMesh,SurfField,
                                            SurfaceQuadrature,STBUP::Tuple,Traction>
                computeSurfaceForces( surfMesh, surfForces, surfaceQuadrature, levelSet, traction );

            SurfaceFieldBinder::FieldIterator first = immersedFieldBinder.elementsBegin();
            SurfaceFieldBinder::FieldIterator  last = immersedFieldBinder.elementsEnd();
            for ( ; first != last; ++first ) {
                
                sumOfForces +=
                    computeSurfaceForces( STBUP::makeTuple( *first ) );
                
            }

            writeSurfaceVTKFile( baseName, step, surfMesh, surfVelocity, surfForces );


            std::cout << "  F= " << sumOfForces.transpose() << " \n";

            forces << time << " " << sumOfForces.transpose() << std::endl;;
        }

    }

    forces.close();

    return 0;
}
Exemplo n.º 5
0
void composition(BVHAccel* bvhAccel, Vector* vertexNormals, int* Faces,
                 PbrtPoint* TextureVertices, int* TextureFaces, PbrtPoint* TextureVertices_D, int* TextureFaces_D, int* adjacencies,// geometry
                 float* I, float* Itexartist, float* Itexdiff, float *Btex, float blendfactor, float* Igroundtex, bool* Igroundmask,
                 float* Idiffuse, float* Idifference, BVHAccel* firstAccel, PbrtPoint* VerticesFirstTransformed,
                 float u0, float v0, float ifu, float ifv, float* groundAxis,// camera parameters
                 float* cTheta, float* sTheta, float* cPhi, float* sPhi, float SphereRadius, Vector* diffuseLight, Vector& ambientLight,// light sphere parameters
                 Vector& albedo, Vector& groundAlbedo,
                 int width, int height, int nt, int nkernels, int ndivs, int nsamp, int shapeIdOffset, int dmapwidth, int dmapheight,
                 int filterhsize, int filtertype, float inv_sigma_sq, // filter parameters
                 string& path, string& direc, string& outputfilename, float* outputimage) { // extra parameters
	
	// intelligent sampling: maybe first sample every 10 pixels or so, and do computations for those pixels
	// then sample remaining pixels, and use them only if they are non-ground or if they are ground and if
	// they are close to shadowed regions of the image.
	
	// Declarations
	int i, ttshapeId, shapeId;
	bool didIntersect, didfirstIntersect;//, didnbdoIntersect, didnbuseIntersect;
	float xpix, ypix, xpixim, ypixim, xdelta, ydelta, lambda;
	float inv_max_rand=1.f/RAND_MAX;
	float barycentrics[3];
	time_t start, end;
    int npixels=width*height;
	//bool useAntiAlias=false;
	//int n_u=(int)sqrtf(ndivs);
	float* Igroundobjmask=new float[npixels];
    float* Iobjmask=new float[npixels];
	
	path=direc;
	
	for (int i=0; i<npixels; i++) {
        Igroundobjmask[i]=Igroundmask[i] ? 1.0f : .0f;
    }
//	memcpy(Igroundobjmask, Igroundmask, npixels*sizeof(float));
	
	float x, y;
	
	Intersection* isect=new Intersection();
	Intersection* lisect=new Intersection();
	Intersection** isects=new Intersection*[4];
	for (i=0; i<4; i++) {
		isects[i]=new Intersection();
	}
	float bcs[3];
		
	Vector direction(.0,.0,1.0), lightDirection, n, reflection;
	PbrtPoint origin(.0,.0,.0);
	PbrtPoint intersectionPt, vdtex, vdtex_d, firstIntersectionPt;
	Ray r(origin,direction,0,INFINITY);
    Ray r2(origin,direction,0,INFINITY);
	Ray s(intersectionPt,lightDirection,0,INFINITY);
	   
	float* colorsamples=new float[3*nsamp*npixels];
	float* finaloutputsamples=new float[3*nsamp*npixels];
	float* lightoutputsamples=new float[3*nsamp*npixels];
	time(&start);
	
	//float stepdox, stepdoy, stepnum=3;;
	//bool didneighborintersect, groupsAreDifferent;
	int idxcol;
	//int nbh=0;
	
	for (i=0; i<3*nsamp*npixels; i++) colorsamples[i]=.0f;
	for (i=0; i<3*nsamp*npixels; i++) lightoutputsamples[i]=.0f;
	for (i=0; i<3*nsamp*npixels; i++) finaloutputsamples[i]=.0f;
	
	for (i=0; i<npixels; i++) {
		
		ypixim=(i % height);
		xpixim=(i / height);
		
		// do a 'pure' (non-random) test here. Based on the intersection flag of that test, test pixels in the
		// surrounding areas. Test points 2 pixels away and half-size pixels away. If there are points 2 pixels
		// away with the opposite intersection flag, mark this pixel as to 'doAntiAlias'.
		
		r.d.x=(xpixim-u0)*ifu; r.d.y=(ypixim-v0)*ifv; r.maxt=INFINITY; r.mint=0;
		didIntersect=bvhAccel->IntersectQ(r,isect,bcs);
		//didIntersect=bvhAccel->IntersectP(r);
		
        
        Igroundobjmask[i]=didIntersect ? 1.0f : Igroundmask[i];
        Iobjmask[i]=didIntersect;
		
        // CHANGED FOR PEN
        //Igroundobjmask[i]=1.0f;
		
        
	}
    
	
    for (i=0; i<4; i++) delete isects[i]; delete[] isects;
    
	
	path=direc;
	
	time(&end);
	double dif;
	dif=difftime(end,start);
	printf("Time taken for figuring which should be anti-aliased=%f seconds.\n",dif);
	
	// if the run number is 0, do everything at a lower sampling rate.
	// at run 1, check the pixels around you that have been sampled; if they are all the same color and ground,
	// there's a high chance you're ground as well, and just copy their color over; that way you can avoid
	// recomputing a whole bunch of things.
	int npixels_covered=0;
	int i3, idxcol1, idxcol2;
	size_t sf3=3*sizeof(float);
	
	time_t startin, endin;
	double difingoforth=0, difinaboveground=0, difinsphere=0, difincolor=0;
	
    time(&start);
    
    
    
    // Lightoutput is the amount of light that comes out (devoid of reflectance)
    // coloredoutput is with the reflectance multipled
    // finaloutput is with the difference tacked on
    Vector diffuselightoutput, coloredoutput, finaloutput;
    
    Vector diffusereflectance;
    Vector appearancedifference;
    
    //i=3084538;
    for (i=0; i<npixels; i++)
    {
        {
            i3=3*i;
            // shoot a ray from the camera center through the pixel (i.e. [x2d,y2d,1])
            ypixim=(i % height);
            xpixim=(i / height);
            
            
            idxcol=3*i; idxcol1=idxcol+1; idxcol2=idxcol+2;
            
            if (abs(Igroundobjmask[i])<1e-3) { //
                memcpy(&colorsamples[idxcol], &Igroundtex[i3], sf3);
                memcpy(&finaloutputsamples[idxcol], &Igroundtex[i3], sf3);
                memcpy(&lightoutputsamples[idxcol], &Igroundtex[i3], sf3);
            } else {
                xpix=xpixim; ypix=ypixim;
                
                r.d.x=(xpix-u0)*ifu;
                r.d.y=(ypix-v0)*ifv;
                r.maxt=INFINITY;
                r.mint=0;
                
                // following tells you if you're ground or not
                didIntersect=bvhAccel->IntersectQ(r,isect,barycentrics);
                
                    time(&startin);
                
                
                npixels_covered++;
                time(&startin);
                //aboveground=true;
                if (!didIntersect) {
                    // if the ray does not intersect with the object,
                    // it might belong the ground
                    lambda=-groundAxis[3]*1.0f/(groundAxis[0]*r.d.x+groundAxis[1]*r.d.y+groundAxis[2]);
                    intersectionPt.x=lambda*r.d.x; intersectionPt.y=lambda*r.d.y; intersectionPt.z=lambda;
                    n=Vector(groundAxis[0],groundAxis[1],groundAxis[2]);
                    
                } else {
                    intersectionPt=r.o+r.d*r.maxt;
                    shapeId=isect->shapeId-shapeIdOffset;
                    ttshapeId=shapeId % nt;
                    
                    n=Normalize(barycentrics[0]*vertexNormals[Faces[3*shapeId]]+
                                barycentrics[1]*vertexNormals[Faces[3*shapeId+1]]+
                                barycentrics[2]*vertexNormals[Faces[3*shapeId+2]]);
                    
                    
                    vdtex=barycentrics[0]*TextureVertices[TextureFaces[3*ttshapeId]]+
                    barycentrics[1]*TextureVertices[TextureFaces[3*ttshapeId+1]]+
                    barycentrics[2]*TextureVertices[TextureFaces[3*ttshapeId+2]];
                    vdtex_d=barycentrics[0]*TextureVertices_D[TextureFaces_D[3*ttshapeId]]+
                    barycentrics[1]*TextureVertices_D[TextureFaces_D[3*ttshapeId+1]]+
                    barycentrics[2]*TextureVertices_D[TextureFaces_D[3*ttshapeId+2]];
                    
                    
                }
                
                time(&endin);
                difinaboveground+=difftime(endin, startin)*1.0f/npixels;
                time(&startin);
                s.o=intersectionPt;
                
                
                // for each pixel in 3D
                //    for each light source
                
                diffuselightoutput=quadrature(intersectionPt, n, r, bvhAccel, diffuseLight, cTheta, sTheta, cPhi, sPhi, SphereRadius, ndivs, groundAxis);
                
                time(&endin);
                difinsphere+=difftime(endin, startin)*1.0/npixels;
                
                time(&startin);
                if (didIntersect) {
                
                    didfirstIntersect=false;
                    
                    if (didfirstIntersect) {
                        x=firstIntersectionPt.x/(firstIntersectionPt.z*ifu)+u0;
                        y=firstIntersectionPt.y/(firstIntersectionPt.z*ifv)+v0;
                        
                        bilinearInterp(x, y, height, Idiffuse, NULL, &diffusereflectance);
                        coloredoutput=Emult(diffuselightoutput,diffusereflectance)+Emult(ambientLight,diffusereflectance);
                        
                        bilinearInterp(x, y, height, Idifference, NULL, &appearancedifference);
                        
                        finaloutput=coloredoutput+appearancedifference;
                    } else {
                        texturescale(vdtex, dmapheight, dmapwidth, &x, &y);
                        
                        
                        // diffuse albedo
                        bilinearInterpTexture(x, y, dmapheight, dmapwidth,Itexartist, Btex, &diffusereflectance,ttshapeId,TextureFaces,TextureVertices,adjacencies);
                        
                        // original image value
                        
                        coloredoutput=Emult(diffuselightoutput,diffusereflectance)+Emult(ambientLight,diffusereflectance);
                        
                        if (Itexdiff !=NULL) {   // may need to change to dmapwidth/dmapheight etc.
                            // texture difference
                            bilinearInterpTexture(x, y, dmapheight, dmapwidth,Itexdiff, Btex, &appearancedifference,ttshapeId,TextureFaces,TextureVertices,adjacencies);
                            finaloutput=coloredoutput+appearancedifference;
                            
                        } else {
                            finaloutput=coloredoutput;
                        }
                    }
                } else {
                    coloredoutput=Emult(diffuselightoutput,groundAlbedo)+Emult(ambientLight,groundAlbedo);
                    finaloutput=coloredoutput+Vector(Igroundtex[i3],Igroundtex[i3+1],Igroundtex[i3+2]);
                    
                }
                
                lightoutputsamples[idxcol]=diffuselightoutput.x > 1.0f ? 1.0f : diffuselightoutput.x; //finaloutputsamples.push_back(color.x);
                lightoutputsamples[idxcol1]=diffuselightoutput.y > 1.0f ? 1.0f : diffuselightoutput.y; //finaloutputsamples.push_back(color.y);
                lightoutputsamples[idxcol2]=diffuselightoutput.z > 1.0f ? 1.0f : diffuselightoutput.z; //finaloutputsamples.push_back(color.z);
                
                colorsamples[idxcol]=coloredoutput.x > 1.0f ? 1.0f : coloredoutput.x; //colorsamples.push_back(colorwithtex.x);
                colorsamples[idxcol1]=coloredoutput.y > 1.0f ? 1.0f : coloredoutput.y; //colorsamples.push_back(colorwithtex.y);
                colorsamples[idxcol2]=coloredoutput.z > 1.0f ? 1.0f : coloredoutput.z; //colorsamples.push_back(colorwithtex.z);
                
                
                finaloutputsamples[idxcol]=finaloutput.x; //finaloutputsamples.push_back(color.x);
                finaloutputsamples[idxcol1]=finaloutput.y; //finaloutputsamples.push_back(color.y);
                finaloutputsamples[idxcol2]=finaloutput.z; //finaloutputsamples.push_back(color.z);
                
                time(&endin);
                difincolor+=difftime(endin, startin)*1.0/npixels;
                
                
            }
        }
        if ( i % height==0) {
            printf("%d of %d columns ( %3.2f %% ) done\n", i / height, width, i*100.0f/npixels);
        }
    }
    
    
    time(&end);
    dif=difftime(end,start);
    
    printf("Cleaning up...\n");
    int resizefactor=2;
    int reswidth= (int)(width/(float)(resizefactor));
    int resheight=(int)(height/(float)(resizefactor));
    float filtersigma=(float)resizefactor/2.0;
    float inv_sigma_squared=1./(2*filtersigma*filtersigma);
    filterhsize=ceil(3*filtersigma);
    int filterwidth=2*filterhsize+1;
    
    float* blurredoutputimage=new float[3*npixels];
    for (int i=0; i<npixels; i++) {
        int xx=i / height;
        int yy=i % height;
        
        blurredoutputimage[i]=.0f;
        float sumweight=.0f;
        for (int sx=-2*filterhsize; sx<=2*filterhsize; sx++) {
            for (int sy=-2*filterhsize; sy<=2*filterhsize; sy++) {
                int xpiximnb=xx+sx; int ypiximnb=yy+sy;
                if (xpiximnb>=0 && xpiximnb<width && ypiximnb>=0 && ypiximnb<height) {
                    int idxnb=((xpiximnb)*height+(ypiximnb));
                    
                    float weight=exp(-inv_sigma_squared*(sx*sx+sy*sy));
                    blurredoutputimage[3*i]+=weight*finaloutputsamples[3*idxnb];
                    blurredoutputimage[3*i+1]+=weight*finaloutputsamples[3*idxnb+1];
                    blurredoutputimage[3*i+2]+=weight*finaloutputsamples[3*idxnb+2];
                    sumweight+=weight;
                }
            }
        }
        blurredoutputimage[3*i]/=sumweight;
        blurredoutputimage[3*i]=blurredoutputimage[3*i]<0.0f ? 0.0f : (blurredoutputimage[3*i] > 1 ? 1.0f : blurredoutputimage[3*i]);
        blurredoutputimage[3*i+1]/=sumweight;
        blurredoutputimage[3*i+1]=blurredoutputimage[3*i+1]<0.0f ? 0.0f : (blurredoutputimage[3*i+1] > 1 ? 1.0f : blurredoutputimage[3*i+1]);
        blurredoutputimage[3*i+2]/=sumweight;
        blurredoutputimage[3*i+2]=blurredoutputimage[3*i+2]<0.0f ? 0.0f : (blurredoutputimage[3*i+2] > 1 ? 1.0f : blurredoutputimage[3*i+2]);
        
        if (xx % 2==0 && yy % 2==0) {
            memcpy(&outputimage[3*( (xx/2)*(resheight)+(yy/2) )], &blurredoutputimage[3*i], 3*sizeof(float));
        }
     }
    
    /*
    for (int w=0; w<reswidth; w++) {
        for (int h=0; h<resheight; h++) {
            int outputindex=w*resheight+h;
            int inputindex=2*w*height+2*h;
            memcpy(&outputimage[3*outputindex], &blurredoutputimage[3*inputindex], 3*sizeof(float));
        }
    }
    */
     
    /*
    cv::Size resizedSize( reswidth,resheight );
    int resizefactor=2;
    double filtersigma=resizefactor/2.0;
    int filterwidth=ceil(6*filtersigma)+1;
    cv::Size filterSize(filterwidth,filterwidth);
    

    path=direc;
    cv::Mat src( width,height,CV_32FC3);
    cv::Mat dst=src.clone();
    cv::GaussianBlur(src, dst, filterSize, filtersigma);
    
    
    cv::Mat_<cv::Vec3b> cvFinalOutputSamples(width,height,cv::Vec3b(0,0,0));
    cv::Mat_<cv::Vec3b> cvBlurFinalOutputSamples(width,height,cv::Vec3b(0,0,0));
    cv::Mat_<cv::Vec3b> cvBlurResizedFinalOutputSamples(reswidth,resheight,cv::Vec3b(0,0,0));
    
    
        cv::GaussianBlur(cvFinalOutputSamples, cvBlurFinalOutputSamples, filterSize, filtersigma);
    memcpy(&(cvFinalOutputSamples.data), finaloutputsamples, 3*sizeof(float)*npixels);
    
    
    cv::resize(cvBlurFinalOutputSamples, cvBlurResizedFinalOutputSamples, resizedSize);
    memcpy(outputimage, &(cvBlurResizedFinalOutputSamples.data), 3*sizeof(float)*reswidth*resheight);
    */
    //memcpy(outputimage, finaloutputsamples, 3*sizeof(float)*npixels);
    
    writeImage(direc, outputimage, reswidth, resheight, string("finaloutput_").append(outputfilename).c_str());
    writeImage(direc, lightoutputsamples, width, height, string("lightoutput_").append(outputfilename).c_str());
    writeImage(direc, colorsamples, width, height, string("coloredoutput_").append(outputfilename).c_str());
    printf("Rendering done, wrote: %s, %s, %s in directory %s\n", string("finaloutput_").append(outputfilename).c_str(),
           string("lightoutput_").append(outputfilename).c_str(), string("coloredoutput_").append(outputfilename).c_str(),
           direc.c_str());
    
	//path=direc; FILE* ffinalid=fopen(path.append("finaloutput_").append(outputfilename).c_str(),"w");
	//path=direc; FILE* fcoloredid=fopen(path.append("coloredoutput_").append(outputfilename).c_str(),"w");
	//path=direc; FILE* flightoutputid=fopen(path.append("lightoutput_").append(outputfilename).c_str(),"w");
	//path=direc; FILE* forigid=fopen(path.append("texturemappedpixels_").append(outputfilename).c_str(),"w");
	
    //fwrite(lightoutputsamples,sizeof(float)*nsamp*npixels*3,1,flightoutputid);
    //fwrite(colorsamples,sizeof(float)*nsamp*npixels*3,1,fcoloredid);
    //fwrite(finaloutputsamples,sizeof(float)*nsamp*npixels*3,1,ffinalid);
    
    //fclose( ffinalid );
    //fclose( fcoloredid );
    //fclose( flightoutputid );
    //fclose( forigid );
	
	delete[] colorsamples;
	delete[] finaloutputsamples;
	delete[] lightoutputsamples;
	delete[] Igroundobjmask;
	delete isect;
	delete lisect;
    //   if (khanmap) delete[] khanmap;
	
	
}
Exemplo n.º 6
0
static double kldivergence(const lambda_a &p, const lambda_b &log_p, lambda_c &log_q,  double a,
                           double b, double eps=0)
{
    auto kl_integral = [&p, &log_p, &log_q](double x){return p(x)*(log_p(x)-log_q(x));};
    return quadrature( kl_integral, a, b, eps);
}
Exemplo n.º 7
0
void wavelet::init(const int type, const int par)
   {
   switch (type)
      {
      // Haar
      case 0:
         {
         g.init(2);
         g = 1;
         }
         break;
         // Beylkin
      case 1:
         {
         const double f[] = {.099305765374, .424215360813, .699825214057,
               .449718251149, -.110927598348, -.264497231446, .026900308804,
               .155538731877, -.017520746267, -.088543630623, .019679866044,
               .042916387274, -.017460408696, -.014365807969, .010040411845,
               .001484234782, -.002736031626, .000640485329};
         g.assign(f, sizeof(f) / sizeof(f[0]));
         }
         break;
         // Coiflet
      case 2:
         {
         switch (par)
            {
            case 1:
               {
               const double f[] = {.038580777748, -.126969125396,
                     -.077161555496, .607491641386, .745687558934,
                     .226584265197};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 2:
               {
               const double f[] = {.016387336463, -.041464936782,
                     -.067372554722, .386110066823, .812723635450,
                     .417005184424, -.076488599078, -.059434418646,
                     .023680171947, .005611434819, -.001823208871,
                     -.000720549445};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 3:
               {
               const double f[] = {-.003793512864, .007782596426,
                     .023452696142, -.065771911281, -.061123390003,
                     .405176902410, .793777222626, .428483476378,
                     -.071799821619, -.082301927106, .034555027573,
                     .015880544864, -.009007976137, -.002574517688,
                     .001117518771, .000466216960, -.000070983303,
                     -.000034599773};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 4:
               {
               const double f[] = {.000892313668, -.001629492013,
                     -.007346166328, .016068943964, .026682300156,
                     -.081266699680, -.056077313316, .415308407030,
                     .782238930920, .434386056491, -.066627474263,
                     -.096220442034, .039334427123, .025082261845,
                     -.015211731527, -.005658286686, .003751436157,
                     .001266561929, -.000589020757, -.000259974552,
                     .000062339034, .000031229876, -.000003259680,
                     -.000001784985};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 5:
               {
               const double f[] = {-.000212080863, .000358589677,
                     .002178236305, -.004159358782, -.010131117538,
                     .023408156762, .028168029062, -.091920010549,
                     -.052043163216, .421566206729, .774289603740,
                     .437991626228, -.062035963906, -.105574208706,
                     .041289208741, .032683574283, -.019761779012,
                     -.009164231153, .006764185419, .002433373209,
                     -.001662863769, -.000638131296, .000302259520,
                     .000140541149, -.000041340484, -.000021315014,
                     .000003734597, .000002063806, -.000000167408,
                     -.000000095158};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
               // Undefined
            default:
               cerr << "Undefined parameter (" << par << ") for wavelet type ("
                     << type << ")." << std::endl;
               return;
            }
         }
         break;
         // Daubechies
      case 3:
         {
         switch (par)
            {
            case 4:
               {
               const double f[] = {.482962913145, .836516303738, .224143868042,
                     -.129409522551};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 6:
               {
               const double f[] = {.332670552950, .806891509311, .459877502118,
                     -.135011020010, -.085441273882, .035226291882};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 8:
               {
               const double f[] = {.230377813309, .714846570553, .630880767930,
                     -.027983769417, -.187034811719, .030841381836,
                     .032883011667, -.010597401785};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 10:
               {
               const double f[] = {.160102397974, .603829269797, .724308528438,
                     .138428145901, -.242294887066, -.032244869585,
                     .077571493840, -.006241490213, -.012580751999,
                     .003335725285};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 12:
               {
               const double f[] = {.111540743350, .494623890398, .751133908021,
                     .315250351709, -.226264693965, -.129766867567,
                     .097501605587, .027522865530, -.031582039317,
                     .000553842201, .004777257511, -.001077301085};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 14:
               {
               const double f[] = {.077852054085, .396539319482, .729132090846,
                     .469782287405, -.143906003929, -.224036184994,
                     .071309219267, .080612609151, -.038029936935,
                     -.016574541631, .012550998556, .000429577973,
                     -.001801640704, .000353713800};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 16:
               {
               const double f[] = {.054415842243, .312871590914, .675630736297,
                     .585354683654, -.015829105256, -.284015542962,
                     .000472484574, .128747426620, -.017369301002,
                     -.044088253931, .013981027917, .008746094047,
                     -.004870352993, -.000391740373, .000675449406,
                     -.000117476784};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 18:
               {
               const double f[] = {.038077947364, .243834674613, .604823123690,
                     .657288078051, .133197385825, -.293273783279,
                     -.096840783223, .148540749338, .030725681479,
                     -.067632829061, .000250947115, .022361662124,
                     -.004723204758, -.004281503682, .001847646883,
                     .000230385764, -.000251963189, .000039347320};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 20:
               {
               const double f[] = {.026670057901, .188176800078, .527201188932,
                     .688459039454, .281172343661, -.249846424327,
                     -.195946274377, .127369340336, .093057364604,
                     -.071394147166, -.029457536822, .033212674059,
                     .003606553567, -.010733175483, .001395351747,
                     .001992405295, -.000685856695, -.000116466855,
                     .000093588670, -.000013264203};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
               // Undefined
            default:
               cerr << "Undefined parameter (" << par << ") for wavelet type ("
                     << type << ")." << std::endl;
               return;
            }
         }
         break;
         // Symmlet
      case 4:
         {
         switch (par)
            {
            case 4:
               {
               const double f[] = {-.107148901418, -.041910965125,
                     .703739068656, 1.136658243408, .421234534204,
                     -.140317624179, -.017824701442, .045570345896};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 5:
               {
               const double f[] = {.038654795955, .041746864422,
                     -.055344186117, .281990696854, 1.023052966894,
                     .896581648380, .023478923136, -.247951362613,
                     -.029842499869, .027632152958};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 6:
               {
               const double f[] = {.021784700327, .004936612372,
                     -.166863215412, -.068323121587, .694457972958,
                     1.113892783926, .477904371333, -.102724969862,
                     -.029783751299, .063250562660, .002499922093,
                     -.011031867509};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 7:
               {
               const double f[] = {.003792658534, -.001481225915,
                     -.017870431651, .043155452582, .096014767936,
                     -.070078291222, .024665659489, .758162601964,
                     1.085782709814, .408183939725, -.198056706807,
                     -.152463871896, .005671342686, .014521394762};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 8:
               {
               const double f[] = {.002672793393, -.000428394300,
                     -.021145686528, .005386388754, .069490465911,
                     -.038493521263, -.073462508761, .515398670374,
                     1.099106630537, .680745347190, -.086653615406,
                     -.202648655286, .010758611751, .044823623042,
                     -.000766690896, -.004783458512};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 9:
               {
               const double f[] = {.001512487309, -.000669141509,
                     -.014515578553, .012528896242, .087791251554,
                     -.025786445930, -.270893783503, .049882830959,
                     .873048407349, 1.015259790832, .337658923602,
                     -.077172161097, .000825140929, .042744433602,
                     -.016303351226, -.018769396836, .000876502539,
                     .001981193736};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 10:
               {
               const double f[] = {.001089170447, .000135245020,
                     -.012220642630, -.002072363923, .064950924579,
                     .016418869426, -.225558972234, -.100240215031,
                     .667071338154, 1.088251530500, .542813011213,
                     -.050256540092, -.045240772218, .070703567550,
                     .008152816799, -.028786231926, -.001137535314,
                     .006495728375, .000080661204, -.000649589896};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
               // Undefined
            default:
               cerr << "Undefined parameter (" << par << ") for wavelet type ("
                     << type << ")." << std::endl;
               return;
            }
         }
         break;
         // Vaidyanathan
      case 5:
         {
         const double f[] = {-.000062906118, .000343631905, -.000453956620,
               -.000944897136, .002843834547, .000708137504, -.008839103409,
               .003153847056, .019687215010, -.014853448005, -.035470398607,
               .038742619293, .055892523691, -.077709750902, -.083928884366,
               .131971661417, .135084227129, -.194450471766, -.263494802488,
               .201612161775, .635601059872, .572797793211, .250184129505,
               .045799334111};
         g.assign(f, sizeof(f) / sizeof(f[0]));
         }
         break;
         // Battle-Lemarie
      case 6:
         {
         switch (par)
            {
            case 1:
               {
               const double f[] = {0.578163, 0.280931, -0.0488618, -0.0367309,
                     0.012003, 0.00706442, -0.00274588, -0.00155701,
                     0.000652922, 0.000361781, -0.000158601, -0.0000867523};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 3:
               {
               const double f[] = {0.541736, 0.30683, -0.035498, -0.0778079,
                     0.0226846, 0.0297468, -0.0121455, -0.0127154, 0.00614143,
                     0.00579932, -0.00307863, -0.00274529, 0.00154624,
                     0.00133086, -0.000780468, -0.00065562, 0.000395946,
                     0.000326749, -0.000201818, -0.000164264, 0.000103307};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
            case 5:
               {
               const double f[] = {0.528374, 0.312869, -0.0261771, -0.0914068,
                     0.0208414, 0.0433544, -0.0148537, -0.0229951, 0.00990635,
                     0.0128754, -0.00639886, -0.00746848, 0.00407882,
                     0.00444002, -0.00258816, -0.00268646, 0.00164132,
                     0.00164659, -0.00104207, -0.00101912, 0.000662836,
                     0.000635563, -0.000422485, -0.000398759, 0.000269842,
                     0.000251419, -0.000172685, -0.000159168, 0.000110709,
                     0.000101113};
               g.assign(f, sizeof(f) / sizeof(f[0]));
               }
               break;
               // Undefined
            default:
               cerr << "Undefined parameter (" << par << ") for wavelet type ("
                     << type << ")." << std::endl;
               return;
            }
         const vector<double> gcopy = g;
         const int len = g.size();
         g.init(2 * len - 1);
         for (int i = 0; i < len; i++)
            g(len - 1 + i) = g(len - 1 - i) = gcopy(i);
         }
         break;
         // Undefined
      default:
         cerr << "Undefined wavelet type (" << type << ")." << std::endl;
         return;
      }
   // normalise g and create quadrature filter
   g /= sqrt(g.sumsq());
   h = quadrature(g);
   // debug information
   trace << "wavelet initialised - type (" << type << ") par (" << par
         << ")." << std::endl;
   trace << "g = " << g << std::endl;
   trace << "h = " << h << std::endl;
   }