bool SpriteModel::insertRows(int position, int rows, const QModelIndex &parent) { if (mSpr == Q_NULLPTR) { bool ok1; int width = QInputDialog::getInt(mParent, tr("Input Width"), tr("Width:"), 25, 1, 2147483647, 1, &ok1); bool ok2; int height = QInputDialog::getInt(mParent, tr("Input Height"), tr("Height:"), 25, 1, 2147483647, 1, &ok2); if (!ok1 || !ok2) insertRows(position, rows, parent); QImage img(width, height, QImage::Format_RGBA8888); img.fill(Qt::gray); mDefault = SubImage(img); mSpr = new Sprite(); } beginInsertRows(QModelIndex(), position, position+rows-1); for (int row = 0; row < rows; ++row) mSpr->mSubimg.insert(position, mDefault); endInsertRows(); return true; }
bool SpriteModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(role); QImage img = value.value<QImage>(); mSpr->mSubimg.replace(index.row(), SubImage(img)); return true; }
cv::Vec3f LightDirection::lightDirectionFromMirrorBall(Mat Image){ const int THRESH = 254; const float radiusOfSphereH = boundingRectForMask.height / 2.0f; const float radiusOfSphereW = boundingRectForMask.width / 2.0f; cout <<endl << "MY Actual center of radius height" << boundingRectForMask.height / 2.0f << endl; cout << endl <<"MY Actual center of radius width " << boundingRectForMask.width / 2.0f << endl; Mat Binary; threshold(Image, Binary, THRESH, 255, CV_THRESH_BINARY); Mat SubImage(Binary, boundingRectForMask); /* calculate center of pixels by using moments from OpenCV. Moments(m00 , m01...) returns the centre of mass of the white pixel against the black pixel Basically moments calculates m00 which is the number of white pixels in a black and white image. m10 is the sum of xcoordinates of white pixels and m01 is sum of ycoordinates of white pixels. */ Moments centerOfMassWhitePixel = moments(SubImage, false); Point center(centerOfMassWhitePixel.m10 / centerOfMassWhitePixel.m00, centerOfMassWhitePixel.m01 / centerOfMassWhitePixel.m00); cv::circle(SubImage, center, 10, 128); //namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display. //imshow("Display window", SubImage); //center.x = 119.5; //center.y = 119.5; std::cout << "x " <<center.x << "y " << center.y << "radius" << radiusOfSphereH; /* x,y are swapped here because opencv later takes x ,y in row coloumn fashion. This one is normalised*/ float euclidianRadius = sqrt(pow((center.x - radiusOfSphereW), 2) + pow((radiusOfSphereH - center.y), 2)); /*std::cout << "Euclidian " << euclidianRadius << std::endl; float cosineTheta = (center.x - radiusOfSphereW) / euclidianRadius; float theta = acos(cosineTheta); float sineTheta = sin(theta); float xDirection = (cosineTheta * euclidianRadius) / radiusOfSphereW; float yDirection = (sineTheta * euclidianRadius) / radiusOfSphereH; float zDirection = sqrt(1.0 - pow(xDirection, 2.0) - pow(yDirection, 2.0));*/ // x,y are swapped here float xDirection = (center.y - radiusOfSphereH) / (radiusOfSphereH); float yDirection = (center.x - radiusOfSphereW) / (radiusOfSphereW); float zDirection = sqrt(1.0 - pow(xDirection, 2.0) - pow(yDirection, 2.0)); //The above xDirection , yDirection ,zDirection gave us the Normal. Hence the following calculation (using reflection formula) to get the actual light direction. // Using L = 2(N dot R)*N- R where R is the direction of camera. i.e. (0 , 0 , -1) orthogonal float x = 2 * xDirection * zDirection; float y = 2 * yDirection * zDirection; float z = 2*pow(zDirection, 2) - 1; return Vec3f(x, y, z); }
void SpriteModel::setSprite(const SpritePtr &spr) { beginResetModel(); if (!spr->isNull()) { QImage img = spr->mSubimg[0].img; img.fill(Qt::gray); mDefault = SubImage(img); } mSpr = spr; endResetModel(); }