예제 #1
0
void QHoneycombWidget::paintGL()
{
  glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT);
  computeTexture();
  
  displayTexture(imWidth, imHeight);
  
  update();
  
  
}
예제 #2
0
///
// Main rendering call for the scene
//
void renderScene(void)
{
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	globalSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE,0);
	computeTexture();
	computeVBO();

	//displayTexture(imWidth, imHeight);
	renderVBO(vbolen);
	glutSwapBuffers();
}
예제 #3
0
void Colormap::computeColors() {
    int left = 0;
    int right = -1;
    for (unsigned i = 1; i < map.size(); i++) {
        if (map[i] != NULLRGB) {
            right = i;
            colors[right] = map[right];
            for (int pos = left + 1; pos < right; pos++) {
                colors[pos] = interpolate(pos, left, right);
            }
            left = right;
            right = -1;
        }
    }
    colors[0] = map[0];
    colors[255] = map[255];


    for (unsigned i = 0; i < 256; i++) {
        float H, S, V;
        rgb2hsv(colors[i].red, colors[i].green, colors[i].blue, H, S, V);
        H = fmod(H + hue, 1.0);
        S = S * saturation;
        hsv2rgb(H, S, V, colors[i].red, colors[i].green, colors[i].blue);
    }

    int step = 256 / numberOfColors;
    for (size_t i = 0; i < 256; i++) {

        int c = step * (int) floor(i / step);
        if (i >= 128) {
            c = c + step - 1;
        }
        colors[i] = colors[c];
    }

    computeTexture();
}
void SoTextureMaskedArea::draw(View2DSliceList *dsl, View2DSlice *dslice, int /*slice*/)
{
   // get size of the original image
   dsl->getImageSize(ox, oy, oz);
   // get size of the mask
   inMask.getSize(mx, my, mz);
   
   // set texture size for build-in textures
   switch (chooseTexture.getValue())
   {
   case 1 :	tx = 2;	ty = 2; tz = 1; tc = 3;
      break;
   case 2 :	tx = 3;	ty = 3; tz = 1; tc = 3;
      break;
   case 3 :	tx = 3;	ty = 3; tz = 1; tc = 3;
      break;
   case 4 :	tx = 1;	ty = 2; tz = 1; tc = 3;
      break;
   case 5 :	tx = 2;	ty = 1; tz = 1; tc = 3;
      break;
   }
   
   // if no valid texture at input and choice is 'from file' -> don't do anything
   if ( !inTexture.isValid() && (chooseTexture.getValue()==0) )
   {
      tx=0; ty=0,tz=0;  tc=0;
      textureOK = false;
   }
   // else -> get size of input texture
   else if( inTexture.isValid() && (chooseTexture.getValue()==0)) inTexture.getSize(tx, ty, tz, tc);
   
   std::cout << "Texture Size is X=" << tx << "   Y=" << ty << "   Z=" << tz << "   C=" << tc << std::endl;
   
   // allocate memory
   textureData = malloc(tc*tx*ty*MLSizeOf(MLuint8Type));
   textureBigData = malloc(3*ox*oy*MLSizeOf(MLuint8Type));
   maskData = malloc(mx*my*MLSizeOf(MLuint8Type));
   originalData = malloc(ox*oy*MLSizeOf(MLuint8Type));
   imageData = malloc(3*ox*oy*MLSizeOf(MLuint8Type));
   
   
   // check masks size -> only draw, if it's equal to original image size
   if ( (mx != ox) || (my != oy) )
   {
      std::cout << "Maske passt nicht zum Originalbild - bitte korrekte Bilder nutzen!" << std::endl;
   }
   else
   {
      // check if memory was allocated
      if ( (textureData == NULL) || (textureBigData == NULL) || (maskData == NULL) || (imageData == NULL) )
      {
         std::cout << "Insufficient memory for allocation available!" << std::endl;
      }
      // if so ->
      else
      {
         // set pointers to image (mask, texture, ...) memory 
         //_ML_UINT8 *tPointer, *tBPointer, *mPointer, *iPointer, *oPointer;
         tPointer	= (_ML_UINT8 *) textureData;
         tBPointer	= (_ML_UINT8 *) textureBigData;
         mPointer	= (_ML_UINT8 *) maskData;
         iPointer	= (_ML_UINT8 *) imageData;
         oPointer	= (_ML_UINT8 *) originalData;
         
         // get original
         oOk = dsl->getInputImage()->getTile3D(originalData, static_cast<MLDataType>(MLuint8Type), 0, 0, currentSlice.getValue(), ox, oy, 1);
         
         // compute texture, if not done already
         if (!textureOK) computeTexture();
         
         
         // Drawing field enabled, i.e. are we supposed to draw?
         if ( drawingOn.getValue() && textureOK )
         {
            // get pointer to overlay texture
            View2DTexture* overlay = dslice->getOverlayTexture(this, 0);
            
            if (drawCounter > 0)
            {
               // we share the lut mode of the View2D
               //if (chooseTexture.getValue() == 0) dsl->getOwner()->updateLutData(_lutFunction, _lutData, &inTexture);
               //else dsl->getOwner()->updateLutData(_lutFunction, _lutData, &inMask);
               dsl->getOwner()->updateLutData(_lutFunction, _lutData, &inTexture, View2DLutPrecision::VIEW2D_LUT_AUTO);
               
               //_lutFunction = new ml::LUTFunction(ml::LUT_RGB, true);
               //_lutFunction->renderRescaled(_lutData, 0x00, 0xFF);
               
               //_lutData->init(ml::LUT_RGB, 0, 0x00, 0xFF);
               
               //_lutFunction = dsl->getOwner()->getDefaultLut();
               
               //_lutFunction->setRelative(true);
               
               //					_lutTransform.setInputLUT(_lutFunction);
               //					_lutTransform.setVisualType(ml::LUT_RGB);
               
               //					_lutData->clear();
               //					_lutFunction->render(_lutData);
               
               
               // set lut, so that the overlay texture is not affected by lut-changes in the original image
               //overlay->setLut(_lutData, dsl->getCurrentCacheContext());
               
               // pass memory area to overlay texture
               overlay->setData(imageData, ox, oy, MLuint8Type, 3);
               drawCounter--;
            }
            
            SbVec3f v, w;
            float vp1[3], vp2[3], vp3[3];
            
            // transform overlay image to slice device coords
            v = SbVec3f(0, 0, 0);
            inMask.mapVoxelToWorld(v, w);
            dslice->mapWorldToDevice(w, vp1[0], vp1[1]);
            v = SbVec3f(mx, 0, 0);
            inMask.mapVoxelToWorld(v, w);
            dslice->mapWorldToDevice(w, vp2[0], vp2[1]);
            v = SbVec3f(0, my, 0);
            inMask.mapVoxelToWorld(v, w);
            dslice->mapWorldToDevice(w, vp3[0], vp3[1]);
            vp1[2] = vp2[2] = vp3[2] = 0;
            
            
            // compose colour with alpha value
            float colour[4];
            colour[0] = overlayColour.getValue()[0]; colour[1] = overlayColour.getValue()[1]; colour[2] = overlayColour.getValue()[2]; colour[3] = overlayAlpha.getValue();
            
            // draw texture
            //dslice->drawTexture(overlay, vp1, vp2, vp3, BLEND_BLEND, colour, dsl->getCurrentCacheContext());
         }
         
         // free memory
         free(textureData);
         free(textureBigData);
         free(maskData);
         free(originalData);
      } // else (memory was allocated)
   } // else (mask size equal original)
}