src/sampler.cc
branchpyrit
changeset 50 14a727b70d07
parent 49 558fde7da82a
child 51 89fec8668768
equal deleted inserted replaced
49:558fde7da82a 50:14a727b70d07
    40 	const int samples = gridsamples[oversample];
    40 	const int samples = gridsamples[oversample];
    41 	if ( phase == 0 )
    41 	if ( phase == 0 )
    42 	{
    42 	{
    43 		cout << "phase 1" << endl;
    43 		cout << "phase 1" << endl;
    44 		phase++;
    44 		phase++;
       
    45 		sx = -1;
    45 		return w*h*samples;
    46 		return w*h*samples;
    46 	}
    47 	}
    47 	else if ( phase == 1 && oversample )
    48 	else if ( phase == 1 && oversample )
    48 	{
    49 	{
    49 		cout << "phase 2" << endl;
    50 		cout << "phase 2" << endl;
    58 		phase = -1;
    59 		phase = -1;
    59 		return 0;
    60 		return 0;
    60 	}
    61 	}
    61 }
    62 }
    62 
    63 
    63 Sample* DefaultSampler::nextSample(Sample *prev)
    64 Sample* DefaultSampler::nextSample()
    64 {
    65 {
    65 	DefaultSample *s = new DefaultSample;
    66 	DefaultSample *s = new DefaultSample;
    66 
    67 
    67 	/* grid oversampling */
    68 	/* grid oversampling */
    68 	static const int gridsamples[] = {1,5,9,16};
    69 	static const int gridsamples[] = {1,5,9,16};
    82 	static const Float *osaSy[] = {NULL, osa5y, osa9y, osa16y};
    83 	static const Float *osaSy[] = {NULL, osa5y, osa9y, osa16y};
    83 	const int samples = gridsamples[oversample];
    84 	const int samples = gridsamples[oversample];
    84 	const Float *osax = osaSx[oversample];
    85 	const Float *osax = osaSx[oversample];
    85 	const Float *osay = osaSy[oversample];
    86 	const Float *osay = osaSy[oversample];
    86 
    87 
    87 	if (!prev)
    88 	if (sx < 0)
    88 	{
    89 	{
    89 		// first sample
    90 		// first sample
    90 		s->x = -(Float)w/h/2.0;
    91 		s->x = -(Float)w/h/2.0;
    91 		s->y = -0.5;
    92 		s->y = -0.5;
    92 		s->sx = 0;
    93 		sx = 0;
    93 		s->sy = 0;
    94 		sy = 0;
    94 		s->osa_samp = 0;
    95 		osa_samp = 0;
    95 	}
    96 	}
    96 	else
    97 	else
    97 	{
    98 	{
    98 		DefaultSample *sp = static_cast<DefaultSample*>(prev);
    99 		osa_samp++;
    99 
   100 
   100 		s->osa_samp = sp->osa_samp + 1;
   101 		if (oversample && oversample <= 3 && osa_samp < samples)
   101 
       
   102 		if (oversample && oversample <= 3 && s->osa_samp < samples)
       
   103 		{
   102 		{
   104 			s->sx = sp->sx;
   103 			s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0;
   105 			s->sy = sp->sy;
   104 			s->y = osay[osa_samp]/h + (Float)sy/h - 0.5;
   106 			s->x = osax[s->osa_samp]/h + (Float)s->sx/h - (Float)w/h/2.0;
       
   107 			s->y = osay[s->osa_samp]/h + (Float)s->sy/h - 0.5;
       
   108 		}
   105 		}
   109 		else
   106 		else
   110 		{
   107 		{
   111 			s->sx = sp->sx + 1;
   108 			sx++;
   112 			s->sy = sp->sy;
   109 			if (sx >= w)
   113 			if (s->sx >= w)
       
   114 			{
   110 			{
   115 				s->sx = 0;
   111 				sx = 0;
   116 				s->sy++;
   112 				sy++;
   117 			}
   113 			}
   118 			if (s->sy >= h)
   114 			if (sy >= h)
   119 			{
   115 			{
   120 				delete s;
   116 				delete s;
   121 				return NULL;
   117 				return NULL;
   122 			}
   118 			}
   123 			s->x = (Float)s->sx/h - (Float)w/h/2.0;
   119 			s->x = (Float)sx/h - (Float)w/h/2.0;
   124 			s->y = (Float)s->sy/h - 0.5;
   120 			s->y = (Float)sy/h - 0.5;
   125 			s->osa_samp = 0;
   121 			osa_samp = 0;
   126 		}
   122 		}
   127 	}
   123 	}
   128 
   124 
   129 	if (s->osa_samp == 0 && oversample && oversample <= 3)
   125 	if (osa_samp == 0 && oversample && oversample <= 3)
   130 	{
   126 	{
   131 		s->x += osax[0]/h;
   127 		s->x += osax[0]/h;
   132 		s->y += osay[0]/h;
   128 		s->y += osay[0]/h;
   133 		Float *buf = buffer + 3*(s->sy*w + s->sx);
   129 		Float *buf = buffer + 3*(sy*w + sx);
   134 		*(buf++) = 0;
   130 		*(buf++) = 0;
   135 		*(buf++) = 0;
   131 		*(buf++) = 0;
   136 		*(buf++) = 0;
   132 		*(buf++) = 0;
   137 	}
   133 	}
   138 
   134 
       
   135 	s->sx = sx;
       
   136 	s->sy = sy;
       
   137 	s->osa_samp = osa_samp;
   139 	return s;
   138 	return s;
   140 }
   139 }
   141 
   140 
   142 void DefaultSampler::saveSample(Sample *samp, Colour &col)
   141 void DefaultSampler::saveSample(Sample *samp, Colour &col)
   143 {
   142 {