static int canEmpty( gdcm::Tag const &tag, const gdcm::Type type ) { switch( type ) { case gdcm::Type::T1 : case gdcm::Type::T1C : return 0; case gdcm::Type::UNKNOWN : return 1; default: return !isSpecial( tag ); } }
/* * Eencoding of the cookies which has special characters. * Useful when profile, session and response attributes contain * special chars and attributes fetch mode is set to HTTP_COOKIE. */ std::string Http::cookie_encode(const std::string& rawString) { std::size_t rawLen = rawString.size(); std::string encodedString; char encodingBuffer[4] = { '%', '\0', '\0', '\0' }; encodedString.reserve(rawLen); for (std::size_t i = 0; i < rawLen; ++i) { char curChar = rawString[i]; if (curChar == ' ') { encodedString += '+'; } else if (isAlpha(curChar) || isDigit(curChar) || isSpecial(curChar)) { encodedString += curChar; } else { unsigned int temp = static_cast<unsigned int>(curChar); encodingBuffer[1] = convertToHexDigit((temp>>4)& 0x0f); encodingBuffer[2] = convertToHexDigit(temp % 0x10); encodedString += encodingBuffer; } } return encodedString; }
void Func::init(int numParams, bool isGenerator) { // For methods, we defer setting the full name until m_cls is initialized m_maybeIntercepted = -1; if (!preClass()) { setNewFuncId(); setFullName(); } else { m_fullName = 0; } if (isSpecial(m_name)) { /* * i) We dont want these compiler generated functions to * appear in backtraces. * * ii) 86sinit and 86pinit construct NameValueTableWrappers * on the stack. So we MUST NOT allow those to leak into * the backtrace (since the backtrace will outlive the * variables). */ m_attrs = m_attrs | AttrNoInjection; } #ifdef DEBUG m_magic = kMagic; #endif assert(m_name); initPrologues(numParams, isGenerator); }
/* * parseArgs * * Parse the command line, stopping at a special symbol of the end of the line. * * args - The array to populate with arguments from line * line - An array of pointers to string corresponding to ALL of the * tokens entered on the command line. * lineIndex - A pointer to the index of the next token to be processed. * This index should point to one element beyond the pipe * symbol. */ static void parseArgs(char** args, char** line, int* lineIndex) { int i; for (i = 0; line[*lineIndex] != NULL && !isSpecial(line[*lineIndex]); ++(*lineIndex), ++i) { args[i] = line[*lineIndex]; } args[i] = NULL; }
// return the next identifier for a tag or an attribute name char * XmlReader::getNextIdent (bool startsWithAlpha) { int startPos = m_pos; char c = getChar (); if (startsWithAlpha && isAlpha (c) == false) { return NULL; } while ( isAlpha (c) || isNumber (c) || isSpecial (c) ) { c = getNextChar (); } //data = m_buffer.substring(m_pos, p); return strdup (m_buffer, startPos, m_pos); }
void runTest() { auto a = m_A; auto b = m_B; for (std::size_t i = 0; i < 1000; ++i) { checkPass(a.is_well_formed() == b.wellFormed()); checkPass(a.is_special() == b.isSpecial()); auto c = a; auto d = b; c.to_special(); d.toSpecial(); checkPass(c.is_well_formed() == d.wellFormed()); checkPass(c.is_special() == d.isSpecial()); a = a + U::one(); b = b + T::one(); } }
TokenTypes Scanner::handleSlash( Token * tok ) { TokenTypes result; int current = nextch(); if( current == S_ENDC ) { HCWarning( RTF_BADEOF, _source->name() ); result = TOK_END; } else if( current == '*' ) { // Certain RTF commands begin with "\*\", not "\". current = nextch(); if( current != '\\' ) { HCWarning( RTF_BADCOMMAND, _lineNum, _source->name() ); if( current != S_ENDC ) { putback( current ); } result = TOK_NONE; } else { result = handleSlash( tok ); } } else if( current == '\n' ) { // A "\" just before a new-line is the same as "\par". memcpy( tok->_text, "par", 4 ); result = TOK_COMMAND; ++_lineNum; } else if( isSpecial( current ) ) { // Some characters are escaped, like "\{". result = TOK_SPEC_CHAR; tok->_value = current; } else if( current == '\'' ) { // "\'nnn" signifies the byte with value nnn. result = TOK_SPEC_CHAR; pullHex( tok ); } else if( islower( current ) ) { // All RTF commands are in lower case. putback( current ); result = TOK_COMMAND; pullCommand( tok ); } else { HCWarning( RTF_BADCOMMAND, _lineNum, _source->name() ); result = TOK_NONE; } return( result ); }
QString KShell::quoteArg( const QString &arg ) { if (!arg.length()) return QString::fromLatin1("''"); for (int i = 0; i < arg.length(); i++) if (isSpecial( arg.unicode()[i] )) { QChar q( QLatin1Char('\'') ); return QString( arg ).replace( q, QLatin1String("'\\''") ).prepend( q ).append( q ); } return arg; }
void SglExprLex::scanSpecial() { int from; from = index; while ( !atEnd() && isSpecial() ) ++index; end = expr.indexOf(escapetag, from); if ( end < 0 || index < end ) end = index; }
std::string Move::algebraic() const { std::string temp; if (!data) { return "0000"; } temp += (from() & 7) + 'a'; temp += (from() >> 3) + '1'; temp += (to() & 7) + 'a'; temp += (to() >> 3) + '1'; if (isSpecial()) { if ((piece() & 7) < Pawn) { temp += " RBQN"[piece() & 7]; } } return temp; }
float VideoFile::numericEpisodeNumber() const { if (isSpecial()) { return SPECIAL; } QRegExp pureNumber("([0-9\\.]+x)?([0-9\\.]+)", Qt::CaseInsensitive); int index = pureNumber.indexIn(episodeNumber); if (index != -1) { // Correction for files that don't have a space after the dash like: // "showname -3", this would be parsed as negative Number. float ep = pureNumber.cap(2).toFloat(); return ep >= 0 ? ep : -1.f * ep; } return UNKNOWN; }
int ViewBubble::assignLigtbubblePositions(glm::vec3* lightbubblePosition, unsigned int lights) { Controller::State::Gameplay& gameplay = *Model::States::get().gameplay; int count = 0; for(auto it = gameplay.getBubbles().getBubbles().begin(); it != gameplay.getBubbles().getBubbles().end(); ++it) { if(it->isSpecial()) { lightbubblePosition[count] = it->getPosition(); ++count; } if(count == lights) break; } return count; }
const Comment* Entity::findClosingTag(const Comment* p, QTextStream& file ){ while (!file.atEnd()) { qint64 pos=file.pos(); QChar c1; file >> c1; const Comment* p2= isSpecial(pos); if (p2!=nullptr){ if (p2->getTag() == p->getClosingTag()) { return p2; } } } return nullptr; }
int unix_dir_loop(Stream_t *Stream, MainParam_t *mp) { DeclareThis(Dir_t); struct dirent *entry; char *newName; int ret=0; #ifdef FCHDIR_MODE int fd; fd = open(".", O_RDONLY); if(chdir(This->pathname) < 0) { fprintf(stderr, "Could not chdir into %s (%s)\n", This->pathname, strerror(errno)); return -1; } #endif while((entry=readdir(This->dir)) != NULL) { if(got_signal) break; if(isSpecial(entry->d_name)) continue; #ifndef FCHDIR_MODE newName = malloc(strlen(This->pathname) + 1 + strlen(entry->d_name) + 1); if(!newName) { ret = ERROR_ONE; break; } strcpy(newName, This->pathname); strcat(newName, "/"); strcat(newName, entry->d_name); #else newName = entry->d_name; #endif ret |= unix_loop(Stream, mp, newName, 0); #ifndef FCHDIR_MODE free(newName); #endif } #ifdef FCHDIR_MODE if(fchdir(fd) < 0) perror("Could not chdir back to .."); close(fd); #endif return ret; }
void Entity::handleTag( const Comment* openingTag, const Comment* closingTag, QTextStream& file, QIODevice& output) { file.seek(openingTag->getCommentEnd()+1); while (!file.atEnd()) { qint64 pos=file.pos(); if (pos>=closingTag->getCommentStart()){ file.seek(closingTag->getCommentEnd()+1); break; } QChar c1; file >> c1; const Comment* p= isSpecial(pos); if (p!=nullptr){ if (p->isAutoClosing()){ // output.write(p->comment); // output.write("<!--REMOVESTART-->"); p->output(this,output); // output.write("<!--REMOVEEND-->"); } else { const Comment* closingTag=findClosingTag(p,file); if (closingTag != nullptr){ QBuffer buf; buf.open(QBuffer::WriteOnly|QBuffer::Text); handleTag(p,closingTag,file,buf); buf.close(); if (false /*p->getTag()==STYLE_START*/){ //embedded_styles.append(buf.buffer()); } else { output.write(buf.buffer()); } } } } else if (isInOuput(pos)){ if (openingTag->isHTML() && c1=='\n'){ output.write(QString("<BR/>").toUtf8()); } else { if (!c1.isNonCharacter()) output.write(QString(c1).toUtf8()); } } } return ; }
void PSCommentLexer::nextStep(char c, State *newState, Action *newAction) { int i = 0; while (true) { Transition trans = transitions[i]; if (trans.c == STOP) { *newState = trans.newState; *newAction = trans.action; return; } bool found = false; if (trans.oldState == m_curState) { switch (trans.c) { case CATEGORY_WHITESPACE : found = isspace(c); break; case CATEGORY_ALPHA : found = isalpha(c); break; case CATEGORY_DIGIT : found = isdigit(c); break; case CATEGORY_SPECIAL : found = isSpecial(c); break; case CATEGORY_LETTERHEX : found = isletterhex(c); break; case CATEGORY_INTTOOLONG : found = m_buffer.length() > MAX_INTLEN; break; case CATEGORY_ANY : found = true; break; default : found = (trans.c == c); } if (found) { *newState = trans.newState; *newAction = trans.action; return; } } i++; } }
std::string Move::string() const { std::string temp; if (!data) { return "null"; } temp += (const char*[]) {"","R","B","Q","N","","K" }[piece() & 7]; temp += (from() & 7) + 'a'; temp += (from() >> 3) + '1'; temp += capture() ? 'x' : '-'; temp += (to() & 7) + 'a'; temp += (to() >> 3) + '1'; if (isSpecial()) { if ((piece() & 7) < Pawn) { temp += " RBQN"[piece() & 7]; temp = temp.substr(1); } else if ((piece() & 7) == King) { if ((to() & 7) == 6) return "O-O"; else return "O-O-O"; } else temp += " ep"; } return temp; }
static QByteArray quote( const QString & s ) { assert( isUsAscii( s ) ); QByteArray r( s.length() * 2, 0 ); bool needsQuotes = false; unsigned int j = 0; for ( int i = 0 ; i < s.length() ; ++i ) { char ch = s[i].toLatin1(); if ( isSpecial( ch ) ) { if ( needsQuoting( ch ) ) r[j++] = '\\'; needsQuotes = true; } r[j++] = ch; } r.truncate( j ); if ( needsQuotes ) return '"' + r + '"'; else return r; }
U_CDECL_BEGIN static UBool U_CALLCONV _processSpecials(const void *context, UChar32 start, UChar32 limit, uint32_t CE) { UErrorCode *status = ((contContext *)context)->status; USet *expansions = ((contContext *)context)->expansions; USet *removed = ((contContext *)context)->removedContractions; UBool addPrefixes = ((contContext *)context)->addPrefixes; UChar contraction[internalBufferSize]; if(isSpecial(CE)) { if(((getCETag(CE) == SPEC_PROC_TAG && addPrefixes) || getCETag(CE) == CONTRACTION_TAG)) { while(start < limit && U_SUCCESS(*status)) { // if there are suppressed contractions, we don't // want to add them. if(removed && uset_contains(removed, start)) { start++; continue; } // we start our contraction from middle, since we don't know if it // will grow toward right or left contraction[internalBufferSize/2] = (UChar)start; addSpecial(((contContext *)context), contraction, internalBufferSize, CE, internalBufferSize/2, internalBufferSize/2+1, status); start++; } } else if(expansions && getCETag(CE) == EXPANSION_TAG) { while(start < limit && U_SUCCESS(*status)) { uset_add(expansions, start++); } } } if(U_FAILURE(*status)) { return FALSE; } else { return TRUE; } }
static int _mwrite_one(Stream_t *Dir, char *argname, char *shortname, write_data_callback *cb, void *arg, ClashHandling_t *ch) { char longname[VBUFSIZE]; const char *dstname; dos_name_t dosname; int expanded; struct scan_state scan; clash_action ret; doscp_t *cp = GET_DOSCONVERT(Dir); expanded = 0; if(isSpecial(argname)) { fprintf(stderr, "Cannot create entry named . or ..\n"); return -1; } if(ch->name_converter == dos_name) { if(shortname) stripspaces(shortname); if(argname) stripspaces(argname); } if(shortname){ convert_to_shortname(cp, ch, shortname, &dosname); if(ch->use_longname & 1){ /* short name mangled, treat it as a long name */ argname = shortname; shortname = 0; } } if (argname[0] && (argname[1] == ':')) { /* Skip drive letter */ dstname = argname + 2; } else { dstname = argname; } /* Copy original argument dstname to working value longname */ strncpy(longname, dstname, VBUFSIZE-1); if(shortname) { ch->use_longname = convert_to_shortname(cp, ch, shortname, &dosname); if(strcmp(shortname, longname)) ch->use_longname |= 1; } else { ch->use_longname = convert_to_shortname(cp, ch, longname, &dosname); } ch->action[0] = ch->namematch_default[0]; ch->action[1] = ch->namematch_default[1]; while (1) { switch((ret=get_slots(Dir, &dosname, longname, &scan, ch))){ case NAMEMATCH_ERROR: return -1; /* Non-file-specific error, * quit */ case NAMEMATCH_SKIP: return -1; /* Skip file (user request or * error) */ case NAMEMATCH_PRENAME: ch->use_longname = convert_to_shortname(cp, ch, longname, &dosname); continue; case NAMEMATCH_RENAME: continue; /* Renamed file, loop again */ case NAMEMATCH_GREW: /* No collision, and not enough slots. * Try to grow the directory */ if (expanded) { /* Already tried this * once, no good */ fprintf(stderr, "%s: No directory slots\n", progname); return -1; } expanded = 1; if (dir_grow(Dir, scan.max_entry)) return -1; continue; case NAMEMATCH_OVERWRITE: case NAMEMATCH_SUCCESS: return write_slots(Dir, &dosname, longname, &scan, cb, arg, ch->use_longname); default: fprintf(stderr, "Internal error: clash_action=%d\n", ret); return -1; } } }
/* isWordChar returns false for spaces */ bool isWordChar(char c) { return isalnum(c) || isSpecial(c); }
/* use: process a <pipeline> args: cmd = root of command tree fdin = input file descriptor return: status of process */ int processPipe(CMD *cmd, int fdin, bool suppress) { int status; // status of process // <stage> | <pipeline> case if (cmd->type == PIPE) { int fd[2]; // file descriptors // build the pipe if (pipe(fd) == -1) { status = errno; errorExit(status); } // built-in command if (isSpecial(cmd->left)) { processSpecial(cmd->left, true); status = processPipe(cmd->right, fd[0], true); return setStat(status); } pid_t pID = fork(); // process ID of fork // error check if (pID < 0) { status = errno; errorExit(status); } // child process else if (pID == 0) { // update input if (fdin != 0) { dup2(fdin, 0); close(fdin); } // update output close(fd[0]); dup2(fd[1], 1); close(fd[1]); // left side of pipe status = processStage(cmd->left); } // parent process else { // close file descriptors if (fdin != 0) { close(fdin); } close(fd[1]); // right side of pipe int temp = processPipe(cmd->right, fd[0], true); // close last file descriptor close(fd[0]); // wait for child process to finish (void) signal(SIGINT, SIG_IGN); waitpid(pID, &status, 0); // update status if (status == 0) { status = temp; } else { status = (WIFEXITED(status) ? WEXITSTATUS(status) : 128+WTERMSIG(status)); } (void) signal(SIGINT, SIG_DFL); } } // <stage> case else { // built-in command if (isSpecial(cmd)) { if (suppress) { status = processSpecial(cmd, true); } else { status = processSpecial(cmd, false); } return setStat(status); } pid_t pID = fork(); // process ID of fork // error check if (pID < 0) { status = errno; errorExit(status); } // child process else if (pID == 0) { // update input if (fdin != 0) { dup2(fdin, 0); close(fdin); } status = processStage(cmd); } // parent process else { //close input if (fdin != 0) { close(fdin); } // wait for child process to finish (void) signal(SIGINT, SIG_IGN); waitpid(pID, &status, 0); // update status status = (WIFEXITED(status) ? WEXITSTATUS(status) : 128+WTERMSIG(status)); (void) signal(SIGINT, SIG_DFL); } } return setStat(status); }
static void addSpecial(contContext *context, UChar *buffer, int32_t bufLen, uint32_t CE, int32_t leftIndex, int32_t rightIndex, UErrorCode *status) { const UCollator *coll = context->coll; USet *contractions = context->conts; USet *expansions = context->expansions; UBool addPrefixes = context->addPrefixes; const UChar *UCharOffset = (UChar *)coll->image+getContractOffset(CE); uint32_t newCE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex)); // we might have a contraction that ends from previous level if(newCE != UCOL_NOT_FOUND) { if(isSpecial(CE) && getCETag(CE) == CONTRACTION_TAG && isSpecial(newCE) && getCETag(newCE) == SPEC_PROC_TAG && addPrefixes) { addSpecial(context, buffer, bufLen, newCE, leftIndex, rightIndex, status); } if(contractions && rightIndex-leftIndex > 1) { uset_addString(contractions, buffer+leftIndex, rightIndex-leftIndex); if(expansions && isSpecial(CE) && getCETag(CE) == EXPANSION_TAG) { uset_addString(expansions, buffer+leftIndex, rightIndex-leftIndex); } } } UCharOffset++; // check whether we're doing contraction or prefix if(getCETag(CE) == SPEC_PROC_TAG && addPrefixes) { if(leftIndex == 0) { *status = U_INTERNAL_PROGRAM_ERROR; return; } --leftIndex; while(*UCharOffset != 0xFFFF) { newCE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex)); buffer[leftIndex] = *UCharOffset; if(isSpecial(newCE) && (getCETag(newCE) == CONTRACTION_TAG || getCETag(newCE) == SPEC_PROC_TAG)) { addSpecial(context, buffer, bufLen, newCE, leftIndex, rightIndex, status); } else { if(contractions) { uset_addString(contractions, buffer+leftIndex, rightIndex-leftIndex); } if(expansions && isSpecial(newCE) && getCETag(newCE) == EXPANSION_TAG) { uset_addString(expansions, buffer+leftIndex, rightIndex-leftIndex); } } UCharOffset++; } } else if(getCETag(CE) == CONTRACTION_TAG) { if(rightIndex == bufLen-1) { *status = U_INTERNAL_PROGRAM_ERROR; return; } while(*UCharOffset != 0xFFFF) { newCE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex)); buffer[rightIndex] = *UCharOffset; if(isSpecial(newCE) && (getCETag(newCE) == CONTRACTION_TAG || getCETag(newCE) == SPEC_PROC_TAG)) { addSpecial(context, buffer, bufLen, newCE, leftIndex, rightIndex+1, status); } else { if(contractions) { uset_addString(contractions, buffer+leftIndex, rightIndex+1-leftIndex); } if(expansions && isSpecial(newCE) && getCETag(newCE) == EXPANSION_TAG) { uset_addString(expansions, buffer+leftIndex, rightIndex+1-leftIndex); } } UCharOffset++; } } }
int main(void) { int ret = 0; INIT_MACHINE(); reg_t numCount = 1; reg_t upCount = 2; reg_t lowCount = 3; reg_t specialCount = 4; reg_t otherCount = 5; reg_t spaceCount = 6; MOVIM8(numCount, 0); MOVIM8(spaceCount, 0); MOVIM8(upCount, 0); MOVIM8(lowCount, 0); MOVIM8(specialCount, 0); MOVIM8(otherCount, 0); reg_t numString = 7; reg_t upString = 9; reg_t lowString = 11; reg_t spaceString = 13; reg_t specialString = 15; reg_t otherString = 17; reg_t newlineString = 19; MOVIM16(numString, ADDR(0)); MOVIM16(spaceString, ADDR(16)); MOVIM16(upString, ADDR(32)); MOVIM16(lowString, ADDR(48)); MOVIM16(specialString, ADDR(64)); MOVIM16(otherString, ADDR(80)); MOVIM16(newlineString, ADDR(96)); reg_t i = 21; // 123456789012 insertString(numString, "numbers = ", i); insertString(spaceString, "spaces = ", i); insertString(upString, "uppers = ", i); insertString(lowString, "lowers = ", i); insertString(specialString, "special = ", i); insertString(otherString, "other = ", i); //endl MOVIM8(REG16(newlineString), '\n'); MOVIM32(REG16(newlineString) + 1, 0); ret = getChar(i); while (ret != (-1)) { if (isUpLetter(i, i+1)) { INC8(upCount); } else if (isLowLetter(i, i+1)) { INC8(lowCount); } else if (isNumber(i, i+1)) { INC8(numCount); } else if (isSpace(i, i+1)) { #ifdef PATCHED INC8(spaceCount); #else INC32(spaceCount); #endif } else if (isSpecial(i, i+1)) { INC8(specialCount); } else { INC8(otherCount); } printChar(i); ret = getChar(i); } printString(numString, i, i+4); printReg8(numCount, i); printString(newlineString, i, i+4); printString(upString, i, i+4); printReg8(upCount, i); printString(newlineString, i, i+4); printString(lowString, i, i+4); printReg8(lowCount, i); printString(newlineString, i, i+4); printString(spaceString, i, i+4); printReg8(spaceCount, i); printString(newlineString, i, i+4); printString(specialString, i, i+4); printReg8(specialCount, i); printString(newlineString, i, i+4); printString(otherString, i, i+4); printReg8(otherCount, i); printString(newlineString, i, i+4); return (0); }
/// Checks if a character is a legal identifier bool NepParser::checkIdentifier(char ch) { return isChar(ch) || isNum(ch) || isSpecial(ch); }
/** Method for creating a 3D or 4D data set * * @param timestep :: index of the time step (4th dimension) in the workspace. * Set to 0 for a 3D workspace. * @param do4D :: if true, create a 4D dataset, else to 3D * @param progressUpdate: Progress updating. passes progress information up the stack. * @return the vtkDataSet created */ vtkDataSet* vtkMDHistoHexFactory::create3Dor4D(size_t timestep, bool do4D, ProgressAction & progressUpdate) const { // Acquire a scoped read-only lock to the workspace (prevent segfault from algos modifying ws) ReadLock lock(*m_workspace); const int nBinsX = static_cast<int>( m_workspace->getXDimension()->getNBins() ); const int nBinsY = static_cast<int>( m_workspace->getYDimension()->getNBins() ); const int nBinsZ = static_cast<int>( m_workspace->getZDimension()->getNBins() ); const coord_t maxX = m_workspace->getXDimension()->getMaximum(); const coord_t minX = m_workspace->getXDimension()->getMinimum(); const coord_t maxY = m_workspace->getYDimension()->getMaximum(); const coord_t minY = m_workspace->getYDimension()->getMinimum(); const coord_t maxZ = m_workspace->getZDimension()->getMaximum(); const coord_t minZ = m_workspace->getZDimension()->getMinimum(); coord_t incrementX = (maxX - minX) / static_cast<coord_t>(nBinsX); coord_t incrementY = (maxY - minY) / static_cast<coord_t>(nBinsY); coord_t incrementZ = (maxZ - minZ) / static_cast<coord_t>(nBinsZ); const int imageSize = (nBinsX ) * (nBinsY ) * (nBinsZ ); vtkPoints *points = vtkPoints::New(); points->Allocate(static_cast<int>(imageSize)); vtkFloatArray * signal = vtkFloatArray::New(); signal->Allocate(imageSize); signal->SetName(m_scalarName.c_str()); signal->SetNumberOfComponents(1); double signalScalar; const int nPointsX = nBinsX+1; const int nPointsY = nBinsY+1; const int nPointsZ = nBinsZ+1; CPUTimer tim; /* The idea of the next chunk of code is that you should only create the points that will be needed; so an array of pointNeeded is set so that all required vertices are marked, and created in a second step. */ // Array of the points that should be created, set to false bool * pointNeeded = new bool[nPointsX*nPointsY*nPointsZ]; memset(pointNeeded, 0, nPointsX*nPointsY*nPointsZ*sizeof(bool)); // Array with true where the voxel should be shown bool * voxelShown = new bool[nBinsX*nBinsY*nBinsZ]; double progressFactor = 0.5/double(nBinsZ); double progressOffset = 0.5; size_t index = 0; for (int z = 0; z < nBinsZ; z++) { //Report progress updates for the first 50% progressUpdate.eventRaised(double(z)*progressFactor); for (int y = 0; y < nBinsY; y++) { for (int x = 0; x < nBinsX; x++) { /* NOTE: It is very important to match the ordering of the two arrays * (the one used in MDHistoWorkspace and voxelShown/pointNeeded). * If you access the array in the wrong way and can't cache it on L1/L2 cache, I got a factor of 8x slowdown. */ //index = x + (nBinsX * y) + (nBinsX*nBinsY*z); if (do4D) signalScalar = m_workspace->getSignalNormalizedAt(x,y,z, timestep); else signalScalar = m_workspace->getSignalNormalizedAt(x,y,z); if (isSpecial( signalScalar ) || !m_thresholdRange->inRange(signalScalar)) { // out of range voxelShown[index] = false; } else { // Valid data voxelShown[index] = true; signal->InsertNextValue(static_cast<float>(signalScalar)); // Make sure all 8 neighboring points are set to true size_t pointIndex = x + (nPointsX * y) + (nPointsX*nPointsY*z); //(Note this index is different then the other one) pointNeeded[pointIndex] = true; pointIndex++; pointNeeded[pointIndex] = true; pointIndex += nPointsX-1; pointNeeded[pointIndex] = true; pointIndex++; pointNeeded[pointIndex] = true; pointIndex += nPointsX*nPointsY - nPointsX - 1; pointNeeded[pointIndex] = true; pointIndex++; pointNeeded[pointIndex] = true; pointIndex += nPointsX-1; pointNeeded[pointIndex] = true; pointIndex++; pointNeeded[pointIndex] = true; } index++; } } } std::cout << tim << " to check all the signal values." << std::endl; // Get the transformation that takes the points in the TRANSFORMED space back into the ORIGINAL (not-rotated) space. Mantid::API::CoordTransform* transform = NULL; if (m_useTransform) transform = m_workspace->getTransformToOriginal(); Mantid::coord_t in[3]; Mantid::coord_t out[3]; // Array with the point IDs (only set where needed) vtkIdType * pointIDs = new vtkIdType[nPointsX*nPointsY*nPointsZ]; index = 0; progressFactor = 0.5/static_cast<double>(nPointsZ); for (int z = 0; z < nPointsZ; z++) { //Report progress updates for the last 50% progressUpdate.eventRaised(double(z)*progressFactor + progressOffset); in[2] = (minZ + (static_cast<coord_t>(z) * incrementZ)); //Calculate increment in z; for (int y = 0; y < nPointsY; y++) { in[1] = (minY + (static_cast<coord_t>(y) * incrementY)); //Calculate increment in y; for (int x = 0; x < nPointsX; x++) { // Create the point only when needed if (pointNeeded[index]) { in[0] = (minX + (static_cast<coord_t>(x) * incrementX)); //Calculate increment in x; if (transform) { transform->apply(in, out); pointIDs[index] = points->InsertNextPoint(out); } else { pointIDs[index] = points->InsertNextPoint(in); } } index++; } } } std::cout << tim << " to create the needed points." << std::endl; vtkUnstructuredGrid *visualDataSet = vtkUnstructuredGrid::New(); visualDataSet->Allocate(imageSize); visualDataSet->SetPoints(points); visualDataSet->GetCellData()->SetScalars(signal); // ------ Hexahedron creation ---------------- // It is approx. 40 x faster to create the hexadron only once, and reuse it for each voxel. vtkHexahedron *theHex = vtkHexahedron::New(); index = 0; for (int z = 0; z < nBinsZ; z++) { for (int y = 0; y < nBinsY; y++) { for (int x = 0; x < nBinsX; x++) { if (voxelShown[index]) { //Only create topologies for those cells which are not sparse. // create a hexahedron topology vtkIdType id_xyz = pointIDs[(x) + (y)*nPointsX + z*nPointsX*nPointsY]; vtkIdType id_dxyz = pointIDs[(x+1) + (y)*nPointsX + z*nPointsX*nPointsY]; vtkIdType id_dxdyz = pointIDs[(x+1) + (y+1)*nPointsX + z*nPointsX*nPointsY]; vtkIdType id_xdyz = pointIDs[(x) + (y+1)*nPointsX + z*nPointsX*nPointsY]; vtkIdType id_xydz = pointIDs[(x) + (y)*nPointsX + (z+1)*nPointsX*nPointsY]; vtkIdType id_dxydz = pointIDs[(x+1) + (y)*nPointsX + (z+1)*nPointsX*nPointsY]; vtkIdType id_dxdydz = pointIDs[(x+1) + (y+1)*nPointsX + (z+1)*nPointsX*nPointsY]; vtkIdType id_xdydz = pointIDs[(x) + (y+1)*nPointsX + (z+1)*nPointsX*nPointsY]; //create the hexahedron theHex->GetPointIds()->SetId(0, id_xyz); theHex->GetPointIds()->SetId(1, id_dxyz); theHex->GetPointIds()->SetId(2, id_dxdyz); theHex->GetPointIds()->SetId(3, id_xdyz); theHex->GetPointIds()->SetId(4, id_xydz); theHex->GetPointIds()->SetId(5, id_dxydz); theHex->GetPointIds()->SetId(6, id_dxdydz); theHex->GetPointIds()->SetId(7, id_xdydz); visualDataSet->InsertNextCell(VTK_HEXAHEDRON, theHex->GetPointIds()); } index++; } } } theHex->Delete(); std::cout << tim << " to create and add the hexadrons." << std::endl; points->Delete(); signal->Delete(); visualDataSet->Squeeze(); delete [] pointIDs; delete [] voxelShown; delete [] pointNeeded; return visualDataSet; }
static bool isEqual(pyston::BoxedString* lhs, pyston::BoxedString* rhs) { if (isSpecial(lhs) || isSpecial(rhs)) return lhs == rhs; return lhs->s() == rhs->s(); }
/** Create the vtkStructuredGrid from the provided workspace @param progressUpdating: Reporting object to pass progress information up the stack. @return fully constructed vtkDataSet. */ vtkDataSet* vtkMDQuadFactory::create(ProgressAction& progressUpdating) const { vtkDataSet* product = tryDelegatingCreation<IMDEventWorkspace, 2>(m_workspace, progressUpdating); if(product != NULL) { return product; } else { IMDEventWorkspace_sptr imdws = this->castAndCheck<IMDEventWorkspace, 2>(m_workspace); // Acquire a scoped read-only lock to the workspace (prevent segfault from algos modifying ws) Mantid::Kernel::ReadLock lock(*imdws); const size_t nDims = imdws->getNumDims(); size_t nNonIntegrated = imdws->getNonIntegratedDimensions().size(); /* Write mask array with correct order for each internal dimension. */ bool* masks = new bool[nDims]; for(size_t i_dim = 0; i_dim < nDims; ++i_dim) { bool bIntegrated = imdws->getDimension(i_dim)->getIsIntegrated(); masks[i_dim] = !bIntegrated; //TRUE for unmaksed, integrated dimensions are masked. } //Ensure destruction in any event. boost::scoped_ptr<IMDIterator> it(imdws->createIterator()); // Create 4 points per box. vtkPoints *points = vtkPoints::New(); points->SetNumberOfPoints(it->getDataSize() * 4); // One scalar per box vtkFloatArray * signals = vtkFloatArray::New(); signals->Allocate(it->getDataSize()); signals->SetName(m_scalarName.c_str()); signals->SetNumberOfComponents(1); size_t nVertexes; vtkUnstructuredGrid *visualDataSet = vtkUnstructuredGrid::New(); visualDataSet->Allocate(it->getDataSize()); vtkIdList * quadPointList = vtkIdList::New(); quadPointList->SetNumberOfIds(4); Mantid::API::CoordTransform* transform = NULL; if (m_useTransform) { transform = imdws->getTransformToOriginal(); } Mantid::coord_t out[2]; bool* useBox = new bool[it->getDataSize()]; double progressFactor = 0.5/double(it->getDataSize()); double progressOffset = 0.5; size_t iBox = 0; do { progressUpdating.eventRaised(progressFactor * double(iBox)); Mantid::signal_t signal_normalized= it->getNormalizedSignal(); if (!isSpecial( signal_normalized ) && m_thresholdRange->inRange(signal_normalized)) { useBox[iBox] = true; signals->InsertNextValue(static_cast<float>(signal_normalized)); coord_t* coords = it->getVertexesArray(nVertexes, nNonIntegrated, masks); delete [] coords; coords = it->getVertexesArray(nVertexes, nNonIntegrated, masks); //Iterate through all coordinates. Candidate for speed improvement. for(size_t v = 0; v < nVertexes; ++v) { coord_t * coord = coords + v*2; size_t id = iBox*4 + v; if(m_useTransform) { transform->apply(coord, out); points->SetPoint(id, out[0], out[1], 0); } else { points->SetPoint(id, coord[0], coord[1], 0); } } // Free memory delete [] coords; } // valid number of vertexes returned else { useBox[iBox] = false; } ++iBox; } while (it->next()); delete[] masks; for(size_t ii = 0; ii < it->getDataSize() ; ++ii) { progressUpdating.eventRaised((progressFactor * double(ii)) + progressOffset); if (useBox[ii] == true) { vtkIdType pointIds = vtkIdType(ii * 4); quadPointList->SetId(0, pointIds + 0); //xyx quadPointList->SetId(1, pointIds + 1); //dxyz quadPointList->SetId(2, pointIds + 3); //dxdyz quadPointList->SetId(3, pointIds + 2); //xdyz visualDataSet->InsertNextCell(VTK_QUAD, quadPointList); } // valid number of vertexes returned } delete[] useBox; signals->Squeeze(); points->Squeeze(); visualDataSet->SetPoints(points); visualDataSet->GetCellData()->SetScalars(signals); visualDataSet->Squeeze(); signals->Delete(); points->Delete(); quadPointList->Delete(); return visualDataSet; } }
short Scanner::getToken( YYSTYPE & lval ) //--------------------------------------- // get the next token from the input stream. // at each call, the next character should be // in _current. { const int MaxBufLen = 512; char buffer[ MaxBufLen ]; int bufPos; // position in buffer char special; gobble(); if( isEOF() ) { return 0; } if( isSpecial() ) { special = (char) _current; get(); // set up for next call return special; // <-------- early return } if( isQuote() ) { readQuotedString( lval ); return T_String; // <-------- early return } if( _current == '0' ) { get(); if( toupper( _current ) == 'X' ) { readHex( lval ); } else { if( isDigit() ) { readDecimal( lval ); } else { lval = 0; } } return T_Number; // <-------- early return } if( isDigit() ) { readDecimal( lval ); return T_Number; // <-------- early return } for( bufPos = 0; bufPos < MaxBufLen; bufPos += 1 ) { buffer[ bufPos ] = (char) _current; get(); if( isEOF() || isSpace() || isSpecial() ) break; } bufPos += 1; assert( bufPos < MaxBufLen ); buffer[ bufPos ] = '\0'; return tokenValue( buffer, lval ); }
static bool isEqual(llvm::StringRef lhs, pyston::BoxedString* rhs) { if (isSpecial(rhs)) return false; return lhs == rhs->s(); }