void applyTransforms(struct trans *tlist, struct GENode *glist) { struct trans *ptl = tlist; struct GENode *pgl = NULL; struct transMatrix m, aux; struct homoCoord start; struct homoCoord end; while(NULL != ptl) { pgl = glist; while(NULL != pgl) { switch(pgl->el.type) { case LINE: initHomoVector(&start, pgl->el.data.line.st.x, pgl->el.data.line.st.y); initHomoVector(&end, pgl->el.data.line.en.x, pgl->el.data.line.en.y); break; default: break; } switch(ptl->tType) { case TRANSLATION: initTranslation(&m, ptl->data.t.tx, ptl->data.t.ty); break; case SCALING: initScale(&m, ptl->data.s.sx, ptl->data.s.sy); if (!(ptl->data.s.px == 0 && ptl->data.s.py == 0)) { initTranslation(&aux, -1*ptl->data.s.px, -1*ptl->data.s.py); matrixProduct(&m, m, aux); initTranslation(&aux, ptl->data.s.px, ptl->data.s.py); matrixProduct(&m, m, aux); } break; case ROTATION: initRotation(&m, ptl->data.r.u); if (!(ptl->data.s.px == 0 && ptl->data.s.py == 0)) { initTranslation(&aux, -1*ptl->data.r.px, -1*ptl->data.r.py); matrixProduct(&m, m, aux); initTranslation(&aux, ptl->data.s.px, ptl->data.s.py); matrixProduct(&m, m, aux); } break; default: break; } matrixVectorProduct(&start, m, start); matrixVectorProduct(&end, m, end); twoDCoord(&pgl->el.data.line.st, start); twoDCoord(&pgl->el.data.line.en, end); pgl = pgl->next; } ptl = ptl->next; } }
int main(int argc, char* argv[]) { TIFF* in; TIFF* out; int c; while ((c = getopt(argc, argv, "w:h:c:")) != -1) { switch (c) { case 'w': tnw = strtoul(optarg, NULL, 0); break; case 'h': tnh = strtoul(optarg, NULL, 0); break; case 'c': contrast = streq(optarg, "exp50") ? EXP50 : streq(optarg, "exp60") ? EXP60 : streq(optarg, "exp70") ? EXP70 : streq(optarg, "exp80") ? EXP80 : streq(optarg, "exp90") ? EXP90 : streq(optarg, "exp") ? EXP : streq(optarg, "linear")? LINEAR : EXP; break; default: usage(); } } if (argc-optind != 2) usage(); out = TIFFOpen(argv[optind+1], "w"); if (out == NULL) return 2; in = TIFFOpen(argv[optind], "r"); if( in == NULL ) return 2; thumbnail = (uint8*) _TIFFmalloc(tnw * tnh); if (!thumbnail) { TIFFError(TIFFFileName(in), "Can't allocate space for thumbnail buffer."); return 1; } if (in != NULL) { initScale(); do { if (!generateThumbnail(in, out)) goto bad; if (!cpIFD(in, out) || !TIFFWriteDirectory(out)) goto bad; } while (TIFFReadDirectory(in)); (void) TIFFClose(in); } (void) TIFFClose(out); return 0; bad: (void) TIFFClose(out); return 1; }
void ImagePyramidFeatureExtractor::init(const Mat& image) { clearLevels(); Mat grayImage = image; if (grayImage.channels() > 1) { Mat temp; cvtColor(grayImage, temp, CV_BGR2GRAY); grayImage = temp; } Size minSize; minSize.height = max(featureSize.height, cvRound(minHeight * image.rows)); minSize.width = max(featureSize.width, cvRound(minSize.height * featureSize.width / featureSize.height)); Size maxSize; maxSize.height = min(image.rows, cvRound(maxHeight * image.rows)); maxSize.width = min(image.cols, cvRound(maxSize.height * featureSize.width / featureSize.height)); double factor = 1; for (int i = 0; ; ++i, factor *= scaleFactor) { Size scaledFeatureSize(cvRound(factor * featureSize.width), cvRound(factor * featureSize.height)); if (scaledFeatureSize.width < minSize.width || scaledFeatureSize.height < minSize.height) continue; if (scaledFeatureSize.width > maxSize.width || scaledFeatureSize.height > maxSize.height) break; // All but the first scaled image use the previous scaled image as the base, // therefore the scaling itself adds more and more blur to the image // and because of that no additional guassian blur is applied. // When scaling the image down a lot, the bilinear interpolation would lead to some artefacts (higher frequencies), // therefore the first down-scaling is done using an area interpolation which produces much better results. // The bilinear interpolation is used for the following down-scalings because of speed and similar results as area. Mat scaledImage; Size scaledImageSize(cvRound(image.cols / factor), cvRound(image.rows / factor)); if (levels.empty()) { firstLevel = i; resize(grayImage, scaledImage, scaledImageSize, 0, 0, cv::INTER_AREA); } else { resize(levels[levels.size() - 1]->getScaledImage(), scaledImage, scaledImageSize, 0, 0, cv::INTER_LINEAR); } initScale(scaledImage); levels.push_back(new PyramidLevel(factor, scaledImage)); } }
/*! \brief Constructor \param align Alignment. \param parent Parent widget */ QwtScaleWidget::QwtScaleWidget( QwtScaleDraw::Alignment align, QWidget *parent): QWidget(parent) { initScale(align); }
/*! \brief Create a scale with the position QwtScaleWidget::Left \param parent Parent widget \param name Object name */ QwtScaleWidget::QwtScaleWidget(QWidget *parent, const char *name): QWidget(parent, name) { initScale(QwtScaleDraw::LeftScale); }
/*! \brief Create a scale with the position QwtScaleWidget::Left \param parent Parent widget */ QwtScaleWidget::QwtScaleWidget(QWidget *parent): QWidget(parent) { initScale(QwtScaleDraw::LeftScale); }
void SystemTopologyDrawing::paintTopology( QPainter &painter, bool optimizeScreen ) { initScale(); int dimIndex[ 3 ]; dimIndex[ 0 ] = -1; dimIndex[ 1 ] = -1; dimIndex[ 2 ] = -1; plane.setFoldingSeparator( data->getFoldingSeparators() ); //if the right mouse is pressed, then we must find the topology item that is selected; //the position of the selected item will be stored in dimIndex; //similarly, if the left mouse was pressed and released at the same position, we //will select the corresponding tree item, and thus need its id int selectedPlane = -1; if ( rightMousePressed || toSelect ) { // get selected plane index Tetragon polygon; polygon.push_back( QPointF( plane.getPoint( 0 )->getX(), plane.getPoint( 0 )->getY() ) ); polygon.push_back( QPointF( plane.getPoint( 1 )->getX(), plane.getPoint( 1 )->getY() ) ); polygon.push_back( QPointF( plane.getPoint( 2 )->getX(), plane.getPoint( 2 )->getY() ) ); polygon.push_back( QPointF( plane.getPoint( 3 )->getX(), plane.getPoint( 3 )->getY() ) ); if ( plane.isRising() ) // check from top to bottom, if user has clicked inside plane { for ( selectedPlane = 0; selectedPlane < ( int )data->getDim( ZZ ); selectedPlane++ ) { //painter.setPen(QPen(Qt::red, 7, Qt::SolidLine)); painter.drawPolygon(polygon); if ( polygon.containsPoint( lastPoint ) ) { break; } polygon.translate( 0, transform->getPlaneDistance() ); } } else // check from bottom to top { polygon.translate( 0, ( ( int )data->getDim( ZZ ) - 1 ) * transform->getPlaneDistance() ); for ( selectedPlane = data->getDim( ZZ ) - 1; selectedPlane >= 0; selectedPlane-- ) { //painter.setPen(QPen(Qt::red, 7, Qt::SolidLine)); painter.drawPolygon(polygon); if ( polygon.containsPoint( lastPoint ) ) { break; } polygon.translate( 0, -transform->getPlaneDistance() ); } } } dimIndex[ ZZ ] = selectedPlane; //if the planes are rising, then we paint the lowest plane first, //otherwise we start with the plane on the top int dummy1 = -1; int dummy2 = -1; if ( plane.isRising() ) { // since the plane is rising, we paint the lowest plane first plane.yScroll( ( double )( data->getDim( ZZ ) - 1 ) * transform->getPlaneDistance() ); //compute which items on planes are visible if the plane is partly //covered by another plane plane.computeVisibles( data, -transform->getPlaneDistance() ); //paint all planes for ( int i = data->getDim( ZZ ) - 1; i >= 0; i-- ) { bool toPaint = true; if ( optimizeScreen ) { //this is the region of this widget which is not covered by other //widgets; only planes in this widget must be painted QRect rect = visibleRegion().boundingRect(); //don't paint if whole plane is below the visible rectangle if ( ( int )plane.getPoint( 0 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 1 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 2 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 3 )->getY() > rect.y() + rect.height() ) { toPaint = false; } //also don't paint if plane is above the visible rectangle else if ( ( int )plane.getPoint( 0 )->getY() < rect.y() && ( int )plane.getPoint( 1 )->getY() < rect.y() && ( int )plane.getPoint( 2 )->getY() < rect.y() && ( int )plane.getPoint( 3 )->getY() < rect.y() ) { toPaint = false; } } // plane.paint method also calculated the index of the selected item if ( toPaint ) { plane.paint( data, i, painter, i > 0, ( i == selectedPlane && ( rightMousePressed || toSelect ) ? &lastPoint : NULL ), ( i == selectedPlane ? dimIndex[ XX ] : dummy1 ), ( i == selectedPlane ? dimIndex[ YY ] : dummy2 ) ); } //scroll the plane to represent the next plane above the //currently painted one if ( i > 0 ) { plane.yScroll( -transform->getPlaneDistance() ); } } } else { //compute which items on planes are visible if the plane is partly //covered by another plane plane.computeVisibles( data, transform->getPlaneDistance() ); //paint all planes; since the plane is not rising, we paint the //plane on the top first for ( unsigned i = 0; i < data->getDim( ZZ ); i++ ) { bool toPaint = true; if ( optimizeScreen ) { //this is the region of this widget which is not covered by other //widgets; only planes in this widget must be painted QRect rect = visibleRegion().boundingRect(); //don't paint if whole plane is below the visible rectangle if ( ( int )plane.getPoint( 0 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 1 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 2 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 3 )->getY() > rect.y() + rect.height() ) { toPaint = false; } //also don't paint if plane is above the visible rectangle else if ( ( int )plane.getPoint( 0 )->getY() < rect.y() && ( int )plane.getPoint( 1 )->getY() < rect.y() && ( int )plane.getPoint( 2 )->getY() < rect.y() && ( int )plane.getPoint( 3 )->getY() < rect.y() ) { toPaint = false; } } if ( toPaint ) { plane.paint( data, i, painter, i < data->getDim( ZZ ) - 1, ( ( int )i == selectedPlane && ( rightMousePressed || toSelect ) ? &lastPoint : NULL ), ( ( int )i == selectedPlane ? dimIndex[ XX ] : dummy1 ), ( ( int )i == selectedPlane ? dimIndex[ YY ] : dummy2 ) ); } if ( i < data->getDim( ZZ ) - 1 ) { plane.yScroll( transform->getPlaneDistance() ); } } //scroll the plane to represent the next plane below the //currently painted one plane.yScroll( -( double )( data->getDim( ZZ ) - 1 ) * transform->getPlaneDistance() ); } QPen pen( Qt::black ); pen.setWidth( 0 ); painter.setPen( pen ); //if the left mouse button was pressed and released without moving //then we select the corresponding item if ( toSelect && dimIndex[ 0 ] != -1 && dimIndex[ 1 ] != -1 && dimIndex[ 2 ] != -1 ) { int systemId = data->getSystemId( dimIndex[ XX ], dimIndex[ YY ], dimIndex[ ZZ ] ); if ( systemId >= 0 ) { selectedSystemId = systemId; } else { selectedSystemId = -1; } } else { selectedSystemId = -1; } if ( rightMousePressed ) // show Tooltip { int x = dimIndex[ XX ]; int y = dimIndex[ YY ]; int z = dimIndex[ ZZ ]; QPoint pos = this->mapToGlobal( lastPoint ); pos.rx() += 5; pos.ry() += 5; info->showInfo( pos, data->getTooltipText( x, y, z ) ); } if ( data->hasInvalidDimensions() ) { painter.setOpacity( 0.7 ); painter.fillRect( this->rect(), Qt::gray ); } }
int render_rift(struct weston_compositor *compositor, GLuint original_program) { struct oculus_rift *rift = compositor->rift; // copy rift->pbuffer into rift->texture /*eglMakeCurrent(rift->egl_display, rift->pbuffer, rift->pbuffer, rift->egl_context); //glClearColor(0.5, 0.0, 0.5, 1.0); //glClear(GL_COLOR_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, rift->texture); eglReleaseTexImage(rift->egl_display, rift->pbuffer, EGL_BACK_BUFFER); eglBindTexImage(rift->egl_display, rift->pbuffer, EGL_BACK_BUFFER); eglMakeCurrent(rift->egl_display, rift->orig_surface, rift->orig_surface, rift->egl_context);*/ // render eyes static int frameIndex = 0; ++frameIndex; ovrPosef eyePoses[2]; ovrHmd_BeginFrameTiming(rift->hmd, frameIndex); ovrHmd_GetEyePoses(rift->hmd, frameIndex, rift->hmdToEyeOffsets, eyePoses, NULL); glEnable(GL_DEPTH_TEST); glUseProgram(rift->eye_shader->program); int i; for(i=0; i<2; i++) { const ovrEyeType eye = rift->hmd->EyeRenderOrder[i]; struct EyeArg eyeArg = rift->eyeArgs[eye]; ovrMatrix4f Model = initTranslationF(0.0, 0.0, rift->screen_z); Model = matrix4fMul(initScale( 3.2 * rift->screen_scale, 1.8 * rift->screen_scale, 1.0), Model); ovrMatrix4f MV = matrix4fMul(posefToMatrix4f(eyePoses[eye]), Model); //MV = initIdentity(); //MV.M[2][3] = 5; glBindFramebuffer(GL_FRAMEBUFFER, eyeArg.framebuffer); glViewport(0, 0, eyeArg.textureWidth, eyeArg.textureHeight); glClearColor(0.0, 0.0, 0.2, 1.0); glClear(GL_COLOR_BUFFER_BIT); glUniform1i(rift->eye_shader->virtualScreenTexture, 0); glUniformMatrix4fv(rift->eye_shader->Projection, 1, GL_FALSE, &eyeArg.projection.M[0][0]); glUniformMatrix4fv(rift->eye_shader->ModelView, 1, GL_FALSE, &MV.M[0][0]); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindTexture(GL_TEXTURE_2D, rift->fbTexture); glBindBuffer(GL_ARRAY_BUFFER, rift->scene->vertexBuffer); glVertexAttribPointer(rift->eye_shader->Position, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL); if(rift->sbs == 1) glBindBuffer(GL_ARRAY_BUFFER, rift->scene->SBSuvsBuffer[eye]); else glBindBuffer(GL_ARRAY_BUFFER, rift->scene->uvsBuffer); glVertexAttribPointer(rift->eye_shader->TexCoord0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); glDrawArrays(GL_TRIANGLES, 0, 6); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); //render_eye(rift, eyeArg); } glBindFramebuffer(GL_FRAMEBUFFER, 0); // render distortion glUseProgram(rift->distortion_shader->program); glViewport(0, 0, 1920, 1080); glClearColor(0.0, 0.1, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_BLEND); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); float angle = 0.0; if(rift->rotate == 1) { angle = 1.57079633; // 90 degrees, in radians glViewport(0, 0, 1080, 1920); } int eye; for(eye=0; eye<2; eye++) { struct EyeArg eyeArg = rift->eyeArgs[eye]; glUniform2fv(rift->distortion_shader->EyeToSourceUVScale, 1, (float *)&eyeArg.scale); glUniform2fv(rift->distortion_shader->EyeToSourceUVOffset, 1, (float *)&eyeArg.offset); glUniform1i(rift->distortion_shader->RightEye, eye); glUniform1f(rift->distortion_shader->angle, angle); glUniform1i(rift->distortion_shader->eyeTexture, 0); //glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, eyeArg.texture); glBindBuffer(GL_ARRAY_BUFFER, eyeArg.vertexBuffer); glVertexAttribPointer(rift->distortion_shader->Position, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); glEnableVertexAttribArray(rift->distortion_shader->Position); glBindBuffer(GL_ARRAY_BUFFER, eyeArg.uvsBuffer[1]); glVertexAttribPointer(rift->distortion_shader->TexCoord0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); glEnableVertexAttribArray(rift->distortion_shader->TexCoord0); glBindBuffer(GL_ARRAY_BUFFER, eyeArg.uvsBuffer[0]); glVertexAttribPointer(rift->distortion_shader->TexCoordR, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); glEnableVertexAttribArray(rift->distortion_shader->TexCoordR); glBindBuffer(GL_ARRAY_BUFFER, eyeArg.uvsBuffer[1]); glVertexAttribPointer(rift->distortion_shader->TexCoordG, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); glEnableVertexAttribArray(rift->distortion_shader->TexCoordG); glBindBuffer(GL_ARRAY_BUFFER, eyeArg.uvsBuffer[2]); glVertexAttribPointer(rift->distortion_shader->TexCoordB, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); glEnableVertexAttribArray(rift->distortion_shader->TexCoordB); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eyeArg.indexBuffer); glDrawElements(GL_TRIANGLES, eyeArg.mesh.IndexCount, GL_UNSIGNED_SHORT, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } //glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); ovrHmd_EndFrameTiming(rift->hmd); // set program back to original shader program glUseProgram(original_program); return 0; }
void CShowGrafView::clear() { initScale(); Invalidate(); }