// Create the board static void createBoard(Game g, int discipline[], int dice[]) { g->gameBoard = malloc (sizeof (struct _board)); assert(g->gameBoard != NULL); // Create the points that exist int x = 0; while (x < NUM_POINTS_X) { int y = 0; while (y < NUM_POINTS_Y) { if (validPoint(x, y)) { createPoint(g, x, y); } y++; } x++; } // Create the regions that exist x = 0; int i = 0; while (x < NUM_REGIONS_X) { int y = 0; while (y < NUM_REGIONS_Y) { if (validRegion(x, y)) { createRegion(g, x, y, i, dice[i], discipline[i]); // Add the region to the points around it addRegionToPoints(g, x, y); i++; } y++; } x++; } }
//Get the hand regions Node* getHandRegions(uint8_t* depth) { Point p1 = createPoint(0,0); Point p2 = createPoint(639, 479); Region full = createRegion(p1, p2); Node* fullRegion = createNode(full); //Segment the image Node* head = segmentRegions(fullRegion, depth, PREV_H); //Throw out small segments head = filterRegions(head); Node* current = head; int handCount = 0; while (current != NULL) { handCount++; current = current->next; } if (!handCount) { printf("No hands detected.\n"); } else if (handCount == 1) { printf("One hand detected.\n"); } else if (handCount == 2) { printf("Two hands detected.\n"); } else { printf("More than two hands detected.\n"); } return head; }
/** * This method is a implementation of the method with the same name defined in the interface IFilterConfigurationDAO. * In this case the rectangle object which corresponds to the region of interest (ROI) is created with information stored * in a text file, this method reads the text file searching a roi tag to find the information and creates a Rectangle object. * In case of the information related with the ROI object cannot be found in the text file this method returns a null pointer.<p> */ Rect* FileReader::getROI(){ string roi_information; findDataByTag(ROI_TAG, roi_information); Rect* p_roi = createRegion(roi_information); if(!p_roi){ cerr << "Error: ROI's information in the file is incorrect." << endl; } return p_roi; }
bool BaseRegion::mimic(BaseRegion *region, float scale, int x, int y) { if (scale == _lastMimicScale && x == _lastMimicX && y == _lastMimicY) { return STATUS_OK; } cleanup(); for (uint32 i = 0; i < region->_points.size(); i++) { int xVal, yVal; xVal = (int)((float)region->_points[i]->x * scale / 100.0f); yVal = (int)((float)region->_points[i]->y * scale / 100.0f); _points.add(new BasePoint(xVal + x, yVal + y)); } _lastMimicScale = scale; _lastMimicX = x; _lastMimicY = y; return createRegion() ? STATUS_OK : STATUS_FAILED; }
void *NclLayoutParser::parseRegion( DOMElement *parentElement, void *objGrandParent) { wclog << "parseRegion" << endl; void *parentObject; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName; void *elementObject; parentObject = createRegion(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE) { element = (DOMElement*)node; elementTagName = XMLString::transcode(element->getTagName()); wclog << ">>" << elementTagName.c_str() << ": "; wclog << XMLString::transcode(element->getAttribute(XMLString::transcode("id"))); if (XMLString::compareIString( elementTagName.c_str(), "region") == 0) { elementObject = parseRegion(element, parentObject); if (elementObject != NULL) { addRegionToRegion(parentObject, elementObject); } } } } return parentObject; }
void generateRegions() { createRegion( APP, app ); createRegion( CORE, core ); createRegion( SYS, sys ); createRegion( EXT, ext ); }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// bool BaseRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // AddPoint ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "AddPoint") == 0) { stack->correctParams(2); int x = stack->pop()->getInt(); int y = stack->pop()->getInt(); _points.add(new BasePoint(x, y)); createRegion(); stack->pushBool(true); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// // InsertPoint ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InsertPoint") == 0) { stack->correctParams(3); int index = stack->pop()->getInt(); int x = stack->pop()->getInt(); int y = stack->pop()->getInt(); if (index >= 0 && index < (int32)_points.size()) { _points.insert_at(index, new BasePoint(x, y)); createRegion(); stack->pushBool(true); } else { stack->pushBool(false); } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// // SetPoint ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetPoint") == 0) { stack->correctParams(3); int index = stack->pop()->getInt(); int x = stack->pop()->getInt(); int y = stack->pop()->getInt(); if (index >= 0 && index < (int32)_points.size()) { _points[index]->x = x; _points[index]->y = y; createRegion(); stack->pushBool(true); } else { stack->pushBool(false); } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// // RemovePoint ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "RemovePoint") == 0) { stack->correctParams(1); int index = stack->pop()->getInt(); if (index >= 0 && index < (int32)_points.size()) { delete _points[index]; _points[index] = nullptr; _points.remove_at(index); createRegion(); stack->pushBool(true); } else { stack->pushBool(false); } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// // GetPoint ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetPoint") == 0) { stack->correctParams(1); int index = stack->pop()->getInt(); if (index >= 0 && index < (int32)_points.size()) { ScValue *val = stack->getPushValue(); if (val) { val->setProperty("X", _points[index]->x); val->setProperty("Y", _points[index]->y); } } else { stack->pushNULL(); } return STATUS_OK; } else { return BaseObject::scCallMethod(script, stack, thisStack, name); } }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool BaseRegion::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(REGION) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(NAME) TOKEN_TABLE(ACTIVE) TOKEN_TABLE(POINT) TOKEN_TABLE(CAPTION) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(EDITOR_SELECTED_POINT) TOKEN_TABLE(PROPERTY) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { _gameRef->LOG(0, "'REGION' keyword expected."); return STATUS_FAILED; } buffer = params; } for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } _points.clear(); while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_CAPTION: setCaption((char *)params); break; case TOKEN_ACTIVE: parser.scanStr((char *)params, "%b", &_active); break; case TOKEN_POINT: { int x, y; parser.scanStr((char *)params, "%d,%d", &x, &y); _points.add(new BasePoint(x, y)); } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_EDITOR_SELECTED_POINT: parser.scanStr((char *)params, "%d", &_editorSelectedPoint); break; case TOKEN_PROPERTY: parseProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in REGION definition"); return STATUS_FAILED; } createRegion(); return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdRegion::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(REGION) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(NAME) TOKEN_TABLE(ACTIVE) TOKEN_TABLE(ZOOM) TOKEN_TABLE(SCALE) TOKEN_TABLE(BLOCKED) TOKEN_TABLE(DECORATION) TOKEN_TABLE(POINT) TOKEN_TABLE(ALPHA_COLOR) TOKEN_TABLE(ALPHA) TOKEN_TABLE(EDITOR_SELECTED_POINT) TOKEN_TABLE(EDITOR_SELECTED) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(CAPTION) TOKEN_TABLE(PROPERTY) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { _gameRef->LOG(0, "'REGION' keyword expected."); return STATUS_FAILED; } buffer = params; } for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } _points.clear(); int ar = 255, ag = 255, ab = 255, alpha = 255; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_CAPTION: setCaption((char *)params); break; case TOKEN_ACTIVE: parser.scanStr((char *)params, "%b", &_active); break; case TOKEN_BLOCKED: parser.scanStr((char *)params, "%b", &_blocked); break; case TOKEN_DECORATION: parser.scanStr((char *)params, "%b", &_decoration); break; case TOKEN_ZOOM: case TOKEN_SCALE: { int j; parser.scanStr((char *)params, "%d", &j); _zoom = (float)j; } break; case TOKEN_POINT: { int x, y; parser.scanStr((char *)params, "%d,%d", &x, &y); _points.add(new BasePoint(x, y)); } break; case TOKEN_ALPHA_COLOR: parser.scanStr((char *)params, "%d,%d,%d", &ar, &ag, &ab); break; case TOKEN_ALPHA: parser.scanStr((char *)params, "%d", &alpha); break; case TOKEN_EDITOR_SELECTED: parser.scanStr((char *)params, "%b", &_editorSelected); break; case TOKEN_EDITOR_SELECTED_POINT: parser.scanStr((char *)params, "%d", &_editorSelectedPoint); break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_PROPERTY: parseProperty(params, false); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in REGION definition"); return STATUS_FAILED; } createRegion(); _alpha = BYTETORGBA(ar, ag, ab, alpha); return STATUS_OK; }
std::unique_ptr< Region > Compositor::createRegion(const QRegion ®ion) { return std::unique_ptr<Region>(createRegion(region, nullptr)); }
Region *Compositor::createRegion(QObject *parent) { return createRegion(QRegion(), parent); }
void getIntensitySumFromOpenCLImage(OpenCLDevice::pointer device, cl::Image2D image, DataType type, float* sum) { // Get power of two size unsigned int powerOfTwoSize = getPowerOfTwoSize(std::max(image.getImageInfo<CL_IMAGE_WIDTH>(), image.getImageInfo<CL_IMAGE_HEIGHT>())); // Create image levels unsigned int size = powerOfTwoSize; size /= 2; std::vector<cl::Image2D> levels; while(size >= 4) { cl::Image2D level = cl::Image2D(device->getContext(), CL_MEM_READ_WRITE, getOpenCLImageFormat(device, CL_MEM_OBJECT_IMAGE2D, TYPE_FLOAT, 1), size, size); levels.push_back(level); size /= 2; } // Compile OpenCL code std::string buildOptions = ""; switch(type) { case TYPE_FLOAT: buildOptions = "-DTYPE_FLOAT"; break; case TYPE_UINT8: buildOptions = "-DTYPE_UINT8"; break; case TYPE_INT8: buildOptions = "-DTYPE_INT8"; break; case TYPE_UINT16: buildOptions = "-DTYPE_UINT16"; break; case TYPE_INT16: buildOptions = "-DTYPE_INT16"; break; } std::string sourceFilename = std::string(FAST_SOURCE_DIR) + "/ImageSum.cl"; std::string programName = sourceFilename + buildOptions; // Only create program if it doesn't exist for this device from before if(!device->hasProgram(programName)) device->createProgramFromSourceWithName(programName, sourceFilename, buildOptions); cl::Program program = device->getProgram(programName); cl::CommandQueue queue = device->getCommandQueue(); // Fill first level size = powerOfTwoSize/2; cl::Kernel firstLevel(program, "createFirstSumImage2DLevel"); firstLevel.setArg(0, image); firstLevel.setArg(1, levels[0]); queue.enqueueNDRangeKernel( firstLevel, cl::NullRange, cl::NDRange(size,size), cl::NullRange ); // Fill all other levels cl::Kernel createLevel(program, "createSumImage2DLevel"); int i = 0; size /= 2; while(size >= 4) { createLevel.setArg(0, levels[i]); createLevel.setArg(1, levels[i+1]); queue.enqueueNDRangeKernel( createLevel, cl::NullRange, cl::NDRange(size,size), cl::NullRange ); i++; size /= 2; } // Get result from the last level unsigned int nrOfElements = 4*4; unsigned int nrOfComponents = getOpenCLImageFormat(device, CL_MEM_OBJECT_IMAGE2D, TYPE_FLOAT, 1).image_channel_order == CL_RGBA ? 4 : 1; float* result = (float*)allocateDataArray(nrOfElements,TYPE_FLOAT,nrOfComponents); queue.enqueueReadImage(levels[levels.size()-1],CL_TRUE,createOrigoRegion(),createRegion(4,4,1),0,0,result); *sum = getSumFromOpenCLImageResult<float>(result, nrOfElements, nrOfComponents); delete[] result; }
cl::size_t<3> createRegion(Vector3ui size) { return createRegion(size.x(), size.y(), size.z()); }
void HandleDating::setSkin(Layout *skin) { _skin = skin; createRegion(); }
void SegmentationRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, float zNear, float zFar, bool mode2D) { std::lock_guard<std::mutex> lock(mMutex); OpenCLDevice::pointer device = std::dynamic_pointer_cast<OpenCLDevice>(getMainDevice()); if(mColorsModified) { // Transfer colors to device (this doesn't have to happen every render call..) std::unique_ptr<float[]> colorData(new float[3*mLabelColors.size()]); std::unordered_map<int, Color>::iterator it; for(it = mLabelColors.begin(); it != mLabelColors.end(); it++) { colorData[it->first*3] = it->second.getRedValue(); colorData[it->first*3+1] = it->second.getGreenValue(); colorData[it->first*3+2] = it->second.getBlueValue(); } mColorBuffer = cl::Buffer( device->getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(float)*3*mLabelColors.size(), colorData.get() ); } if(mFillAreaModified) { // Transfer colors to device (this doesn't have to happen every render call..) std::unique_ptr<char[]> fillAreaData(new char[mLabelColors.size()]); std::unordered_map<int, Color>::iterator it; for(it = mLabelColors.begin(); it != mLabelColors.end(); it++) { if(mLabelFillArea.count(it->first) == 0) { // Use default value fillAreaData[it->first] = mFillArea; } else { fillAreaData[it->first] = mLabelFillArea[it->first]; } } mFillAreaBuffer = cl::Buffer( device->getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(char)*mLabelColors.size(), fillAreaData.get() ); } mKernel = cl::Kernel(getOpenCLProgram(device), "renderToTexture"); mKernel.setArg(2, mColorBuffer); mKernel.setArg(3, mFillAreaBuffer); mKernel.setArg(4, mBorderRadius); mKernel.setArg(5, mOpacity); for(auto it : mDataToRender) { Image::pointer input = std::static_pointer_cast<Image>(it.second); uint inputNr = it.first; if(input->getDimensions() != 2) throw Exception("SegmentationRenderer only supports 2D images. Use ImageSlicer to extract a 2D slice from a 3D image."); if(input->getDataType() != TYPE_UINT8) throw Exception("SegmentationRenderer only support images with dat type uint8."); // Check if a texture has already been created for this image if(mTexturesToRender.count(inputNr) > 0 && mImageUsed[inputNr] == input) continue; // If it has already been created, skip it // If it has not been created, create the texture OpenCLImageAccess::pointer access = input->getOpenCLImageAccess(ACCESS_READ, device); cl::Image2D *clImage = access->get2DImage(); // Run kernel to fill the texture cl::CommandQueue queue = device->getCommandQueue(); if (mTexturesToRender.count(inputNr) > 0) { // Delete old texture glDeleteTextures(1, &mTexturesToRender[inputNr]); mTexturesToRender.erase(inputNr); glDeleteVertexArrays(1, &mVAO[inputNr]); mVAO.erase(inputNr); } cl::Image2D image; cl::ImageGL imageGL; std::vector<cl::Memory> v; GLuint textureID; // TODO The GL-CL interop here is causing glClear to not work on AMD systems and therefore disabled /* if(DeviceManager::isGLInteropEnabled()) { // Create OpenGL texture glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, input->getWidth(), input->getHeight(), 0, GL_RGBA, GL_FLOAT, 0); // Create CL-GL image imageGL = cl::ImageGL( device->getContext(), CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0, textureID ); glBindTexture(GL_TEXTURE_2D, 0); glFinish(); mKernel.setArg(1, imageGL); v.push_back(imageGL); queue.enqueueAcquireGLObjects(&v); } else { */ image = cl::Image2D( device->getContext(), CL_MEM_READ_WRITE, cl::ImageFormat(CL_RGBA, CL_FLOAT), input->getWidth(), input->getHeight() ); mKernel.setArg(1, image); //} mKernel.setArg(0, *clImage); queue.enqueueNDRangeKernel( mKernel, cl::NullRange, cl::NDRange(input->getWidth(), input->getHeight()), cl::NullRange ); /*if(DeviceManager::isGLInteropEnabled()) { queue.enqueueReleaseGLObjects(&v); } else {*/ // Copy data from CL image to CPU auto data = make_uninitialized_unique<float[]>(input->getWidth() * input->getHeight() * 4); queue.enqueueReadImage( image, CL_TRUE, createOrigoRegion(), createRegion(input->getWidth(), input->getHeight(), 1), 0, 0, data.get() ); // Copy data from CPU to GL texture glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, input->getWidth(), input->getHeight(), 0, GL_RGBA, GL_FLOAT, data.get()); glBindTexture(GL_TEXTURE_2D, 0); glFinish(); //} mTexturesToRender[inputNr] = textureID; mImageUsed[inputNr] = input; queue.finish(); } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); drawTextures(perspectiveMatrix, viewingMatrix, mode2D); glDisable(GL_BLEND); }