예제 #1
0
void ZSparseObject::display(ZPainter &painter, int z, EDisplayStyle option) const
{
  if (m_stackGrid.isEmpty() || z < 0) {
    ZObject3dScan::display(painter, z, option);
  } else {
    UNUSED_PARAMETER(option);
    z -= iround(painter.getZOffset());
    QPen pen(m_color);
    painter.setPen(pen);

    size_t stripeNumber = getStripeNumber();
    for (size_t i = 0; i < stripeNumber; ++i) {
      const ZObject3dStripe &stripe = getStripe(i);
      if (stripe.getZ() == z) {
        int nseg = stripe.getSegmentNumber();
        for (int j = 0; j < nseg; ++j) {
          int x0 = stripe.getSegmentStart(j);
          int x1 = stripe.getSegmentEnd(j);
          int y = stripe.getY();
          for (int x = x0; x <= x1; ++x) {
            int v = getVoxelValue(x, y, z);
            painter.setPen(QColor(v, v, v));
            painter.drawPoint(QPoint(x, y));
          }
        }
      }
    }
  }
}
예제 #2
0
void ZSparseObject::setVoxelValue(ZStack *stack)
{
#if defined(_USE_OPENVDB_2)

#ifdef _DEBUG_2
  stack->save(GET_TEST_DATA_DIR + "/test.tif");
#endif

  if (stack != NULL && stack->kind() == GREY) {
    int z0 = stack->getOffset().getZ();
    int z1 = z0 + stack->depth() - 1;
    int y0 = stack->getOffset().getY();
    int y1 = y0 + stack->height() - 1;
    int x0 = stack->getOffset().getX();
    int x1 = x0 + stack->width() - 1;

#ifdef _DEBUG_2
  clear();
  for (int y = y0; y <= y1; ++y) {
    addStripe(z0, y);
    addSegment(x0, x1);
  }

#endif

    size_t area = stack->width() * stack->height();
    uint8_t *array = stack->array8();
    for (size_t i = 0; i < getStripeNumber(); ++i) {
      const ZObject3dStripe &stripe = getStripe(i);
      int y = stripe.getY();
      int z = stripe.getZ();
      if (IS_IN_CLOSE_RANGE(z, z0, z1) &&
          IS_IN_CLOSE_RANGE(y, y0, y1)) {
        for (int j = 0; j < stripe.getSegmentNumber(); ++j) {
          int tx0 = imax2(x0, stripe.getSegmentStart(j));
          int tx1 = imin2(x1, stripe.getSegmentEnd(j));

          size_t offset = area * (z - z0) + stack->width() * (y - y0) +
              tx0 - x0;
          for (int x = tx0; x <= tx1; ++x) {
            m_voxelValueObject.setValue(x, y, z, array[offset++]);
          }
        }
      }
    }
    m_voxelValueObject.repack();
  }
#endif
}
예제 #3
0
// shaded white stones
void ImageHandler::paintWhiteStone (QImage &wi, int d, int stone_render)//bool stripes ) {
{
	WhiteDesc desc;
	decideAppearance(&desc, d);

	// the angle from which the dim starts (measured to the light direction = pi/4)
	// alpha should be in (0, pi)
	const double ALPHA = M_PI/4;
	// how big the dim is (should be < d/2)
	const double STRIPE = d/5.0;

	double theta;
	const double pixel=0.8;//, shadow=0.99;

	bool Alias=true;
	
	// these are the images
	int i, j, g, g1,g2,k;
	double di, dj, d2=(double)d/2.0-5e-1, r=d2-2e-1, f=sqrt(3.0);
	double x, y, z, xr, xr1, xr2, xg1,xg2, hh;
	
	k=0;
	
	bool smallerstones = false;
	if (smallerstones) r-=1;

	for (i=0; i<d; i++)
		for (j=0; j<d; j++) {
			di=i-d2; dj=j-d2;
			hh=r-sqrt(di*di+dj*dj);
			if (hh>=0) 
			{
				if (stone_render != 1)
				{
					z=r*r-di*di-dj*dj;
					if (z>0) z=sqrt(z)*f;
					else z=0;
					x=di; y=dj;
					xr=sqrt(6*(x*x+y*y+z*z));
					xr1=(2*z-x+y)/xr;
					xr2=(2*z+x-y)/xr;
				
//#define WHITE_SHINE_START			0.9
//#define WHITE_SHINE_END			0.92
#define WHITE_SHINE_START			0.9795
#define WHITE_SHINE_END				0.98
					if (xr1>WHITE_SHINE_START) xg1=(xr1-WHITE_SHINE_START)*10;
					else xg1=0;

					if (xr2>WHITE_SHINE_END) xg2=(xr2-WHITE_SHINE_END)*10;
					else xg2=0;
//#define WHITENESS					200
#define WHITENESS					235
//#define WHITENESS_SHINE			10
#define WHITENESS_SHINE				5
					g2=(int)(WHITENESS+WHITENESS_SHINE* xr2+xg2*45);
				//g=(g1 > g2 ? g1 : g2);
				
					theta = atan2(double(j-d/2), double(i-d/2)) + M_PI - M_PI/4 + M_PI/2;
					bool stripeband = theta > ALPHA && theta < 2*M_PI-ALPHA;

					if (theta > M_PI) 
					theta = (2*M_PI-theta);

					double stripe = STRIPE*sin((M_PI/2)*(theta-ALPHA)/(M_PI-ALPHA));
					if (stripe < 1) stripe = 1;
				
					double g1min=(int)(0+WHITENESS_SHINE*xr1+xg1*45), g2min=(int)(0+WHITENESS_SHINE*xr2+xg2*45);
					double g1max=(int)(WHITENESS+WHITENESS_SHINE*xr1+xg1*45), g2max=(int)(WHITENESS+WHITENESS_SHINE* xr2+xg2*45);;
					g1min = g1max - (g1max-g1min)*(1-exp(-1*(theta-ALPHA)/(M_PI-ALPHA)));
					g2min = g2max - (g2max-g2min)*(1-exp(-1*(theta-ALPHA)/(M_PI-ALPHA)));
				
					if ((hh < STRIPE) && hh > pixel && stripeband) 
					{
					
						if (hh > stripe) g1 = (int)g1max;
						else g1 = int(g1min + (g1max-g1min)*sqrt(hh/stripe));
					
						if (hh > stripe) g2 = (int)g2max;
						else g2 = int(g2min + (g2max-g2min)*sqrt(hh/stripe));
					
						g=(g1 > g2 ? g1 : g2);
					
						if (stone_render == 0) //stripes)
							g = (int)getStripe(desc, g, xr1/7.0, i, j);
						painting_buffer[k]=(255<<24)|(g<<16)|((g)<<8)|(g);
					}
					else if (( hh > pixel ) || (!Alias) )
					{
					//g1=(int)(190+10*drand48()+10*xr1+xg1*45);
					
						g=(int)(g1max > g2max ? g1max : g2max);
					
						if (stone_render == 0)//stripes)
							g = (int)getStripe(desc, g, xr1/7.0, i, j);
						painting_buffer[k]=(255<<24)|(g<<16)|((g)<<8)|(g);
					}
					else {
					
						g1=(int)(stripeband ? g1min : g1max);
						g2=(int)(stripeband ? g2min : g2max);
					
						g=(g1 > g2 ? g1 : g2);
					
						if (stone_render == 0)//stripes)
							g = (int)getStripe(desc, g, xr1/7.0, i, j);
				
						painting_buffer[k]=((int)(hh/pixel*255)<<24)|(g<<16)|(g<<8)|g;				
					}
				}
				else // Code for flat stones
				{
					// draws a black circle for 2D stones
					if ((hh>=-1)&&(hh<=1))
					{
						g=0;
						painting_buffer[k]=((int)(255)<<24)|(g<<16)|(g<<8)|g;
					}	
					else if (hh>0)
					{
						g=255;
						painting_buffer[k]=((int)(255)<<24)|(g<<16)|(g<<8)|g;
					}
				}	
				
			}
			else painting_buffer[k]=0;
			k++;
		}

	// now copy the result in QImages
	icopy(painting_buffer, wi, d, d);
}