Exemplo n.º 1
0
void GroupControler::onListChanged(std::vector<std::shared_ptr<service::User> > group)
{
    qDebug() << Q_FUNC_INFO<<group.size();
    GroupList groupList;
    for(auto i:group){
        std::shared_ptr<service::TinyGroup> tg = std::dynamic_pointer_cast<service::TinyGroup>(i);
        Group gp;
        gp.avatar=QString::fromStdString(tg->avatar);
        gp.createrid=QString::number(tg->createrid);
        qDebug() << Q_FUNC_INFO<<"wwwwwwwwww :"<<gp.createrid;
        //        QDateTime DateTime;
        //        DateTime.setMSecsSinceEpoch(gro->create_time);
        //        group.create_time=DateTime.toString("MM月dd日") +QString::fromLocal8Bit(" ")+DateTime.toString("HH:mm");
        gp.extend=QString::fromStdString(tg->extends);
        gp.id=QString::number(tg->id);
        gp.level=QString::number(tg->level);
        gp.name=QString::fromStdString(tg->name);
        std::string str;
        str=tg->pinyin.substr(0,1);
        str[0]=str[0]-32;
        if(str[0]<'A'||str[0]>'Z'){
            str[0]='#';
        }

        gp.pinyin=QString::fromStdString(str);
        qDebug() << Q_FUNC_INFO<<gp.pinyin<<"zhelizheliezheli";
        gp.server=QString::fromStdString(tg->server);
        gp.thumbAvatar=QString::fromStdString(tg->thumb_avatar);

        qDebug() << Q_FUNC_INFO<<"wwwwwwwwww"<<gp.thumbAvatar;
        gp.timeZone=QString::number(tg->time_zone);
        groupList.push_back(gp);
    }
    emit groupListChanged(groupList);
}
Exemplo n.º 2
0
bool
OSXKeyState::getGroups(GroupList& groups) const
{
	CFIndex n;
	bool gotLayouts = false;

	// get number of layouts
	CFStringRef keys[] = { kTISPropertyInputSourceCategory };
	CFStringRef values[] = { kTISCategoryKeyboardInputSource };
	CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
	CFArrayRef kbds = TISCreateInputSourceList(dict, false);
	n = CFArrayGetCount(kbds);
	gotLayouts = (n != 0);

	if (!gotLayouts) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}

	// get each layout
	groups.clear();
	for (CFIndex i = 0; i < n; ++i) {
		bool addToGroups = true;
		TISInputSourceRef keyboardLayout = 
			(TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);

		if (addToGroups)
    		groups.push_back(keyboardLayout);
	}
	return true;
}
Exemplo n.º 3
0
void CPdpManager::SortGroups()
{
	//here is a little hack to sort the groups into the correct order so that they
	//will save out properly.

	GroupList gListSort = m_GroupList;
	sort(gListSort.begin(), gListSort.end());
	for (int newIdx = 0; newIdx < (int)gListSort.size(); newIdx++)
	{
		if (gListSort[newIdx] != m_GroupList[newIdx])
		{
			int oldIdx = 0;
			for (oldIdx = 0; oldIdx < (int)m_GroupList.size(); oldIdx++)
			{
				if (m_GroupList[oldIdx] == gListSort[newIdx])
				{
					dprintf("%s - old: %d, new: %d\n", m_GroupList[oldIdx].c_str(), oldIdx, newIdx);
					break;
				}
			}
			assert(oldIdx != gListSort.size());

			for (FileListItr itr = m_FileList.begin(); itr != m_FileList.end(); itr++)
			{
				if (itr->nGroupInx == oldIdx)
				{
					//set the new index to the negative value so it doesn't get re-remapped
					itr->nGroupInx = -newIdx;
				}
			}
		}
	}
	m_GroupList = gListSort;

	//fix the negative indexes.
	for (FileListItr itr = m_FileList.begin(); itr != m_FileList.end(); itr++)
	{
		if (itr->nGroupInx < 0)
			itr->nGroupInx = -itr->nGroupInx;
	}

	sort(m_FileList.begin(), m_FileList.end(), CPdpManager::SFileCompare);

	for (FileListItr itr = m_FileList.begin(); itr != m_FileList.end(); itr++)
	{
		dprintf(itr->filename.c_str());
		dprintf("\n");
	}
		
}
Exemplo n.º 4
0
GroupList *unmarshalGroupList(StorageIntf *s)
{
  uint i;
  uint count = unmarshalUInt(s);
  if (count==NULL_LIST) return 0; // null list
  assert(count<1000000);
  GroupList *result = new GroupList;
  for (i=0;i<count;i++)
  {
    GroupDef *gd = (GroupDef *)unmarshalObjPointer(s);
    result->append(gd);
  }
  return result;
}
Exemplo n.º 5
0
bool WorldManager::_handleGroupObjectTimers(uint64 callTime, void* ref)
{
    //iterate through all groups and update the missionwaypoints
    GroupList* groupList = gGroupManager->getGroupList();
    GroupList::iterator it = groupList->begin();

    while(it != groupList->end())
    {
        GroupObject* group = (*it);
        gGroupManager->sendGroupMissionUpdate(group);
        it++;
    }

    return (true);
}
Exemplo n.º 6
0
/*!
  Insert Parameters in AST of given scad file
  form of annotations
*/
void CommentParser::collectParameters(const char *fulltext, FileModule *root_module)
{
	// Get all groups of parameters
	GroupList groupList = collectGroups(std::string(fulltext));
	int parseTill=getLineToStop(fulltext);
	// Extract parameters for all literal assignments
	for (auto &assignment : root_module->scope.assignments) {
		if (!assignment.expr.get()->isLiteral()) continue; // Only consider literals

		// get location of assignment node
		int firstLine = assignment.location().firstLine();
		if(firstLine>=parseTill ) continue;

		// making list to add annotations
		AnnotationList *annotationList = new AnnotationList();
 
		// Extracting the parameter comment
		std::string comment = getComment(std::string(fulltext), firstLine);
		// getting the node for parameter annnotataion
		shared_ptr<Expression> params = CommentParser::parser(comment.c_str());
		if (!params) {
			params = shared_ptr<Expression>(new Literal(ValuePtr(std::string(""))));
		}

		// adding parameter to the list
		annotationList->push_back(Annotation("Parameter", params));

		//extracting the description
		std::string descr = getDescription(std::string(fulltext), firstLine - 1);
		if (descr != "") {
			//creating node for description
			shared_ptr<Expression> expr(new Literal(ValuePtr(std::string(descr.c_str()))));
			annotationList->push_back(Annotation("Description", expr));
		}

		// Look for the group to which the given assignment belong
		int i=0;
		for (;i<groupList.size() && groupList[i].lineNo<firstLine;i++);
		i--;

		if (i >= 0) {
			//creating node for description
			shared_ptr<Expression> expr(new Literal(ValuePtr(groupList[i].commentString)));
			annotationList->push_back(Annotation("Group", expr));
		}
		assignment.addAnnotations(annotationList);
	}
}
void ContactsTreeWidget::loadAvatars() {
  appInstance->logEvent("ContactsTreeWidget::loadAvatars()", SEVERITY_DEBUG);
  GroupList *gl = appInstance->mUser->getGroupList();
  ContactList *cl;
  ContactList::iterator c**t;
  GroupList::iterator glIt;
  for(glIt = gl->begin(); glIt != gl->end(); glIt++) {
    cl = glIt->second.contacts();
    for(c**t = cl->begin(); c**t != cl->end(); c**t++) {
      if (addedContacts[c**t->getIndex()]) {
        c**t->setAvatar(MrimUtils::prepareAvatar(c**t->getAddress()));
        addedContacts[c**t->getIndex()][columns.contactAvatar] = resizeAvatar(c**t->getAvatar());
      }
    }
  }
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
   Kernel::installDefaultPrint();

   // Build a name -> order map for faster lookups.
   for (int i = 0; i < sizeof(OrderTable) / sizeof(const char*); i++)
      OutputOrder.insert(String(OrderTable[i]),i+1);

   GroupList extensions;
   extensions.reserve(800);
   loadDir(extensions,"core","VERSION");
   loadDir(extensions,"extensions","*");
   outputHeader(extensions,"glext.h");
   outputFunctions(extensions,"glfnext.h");

   return 0;
}
Exemplo n.º 9
0
void outputFunctions(GroupList& groups, String name)
{
   FILE* file = fopen(name.c_str(),"w");
   if (!file)
      Print("Could not open file " + name);

   // Output the functions for each group
   for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++) {
      if (!grp->name)
         continue;
      if (grp->name == "GL_ARB_imaging")
         // Imaging is include as part of 1.4...
         write(file,"\n#if defined(GL_ARB_imaging) && !defined(GL_VERSION_1_4)\n");
      else
         write(file,"\n#ifdef " + grp->name + "\n");
      write(file,"GL_GROUP_BEGIN(" + grp->name + ")\n");
      for (Array<String>::Iterator itr = grp->functions.begin();
            itr != grp->functions.end(); itr++) {
         String& str = *itr;

         // Parse function "return name (args)".  Start at the back because
         // args is enclosed in (), the name has no spaces, and the return type
         // can be several tokens, such as "void *" or "const char *"
         int b = str.length();
         int a = b - 1;
         while (str[a] != '(')
            a--;
         String args = str.substr(a,b - a);

         while (str[--a] == ' ')
            ;
         b = a;
         while (str[a] != ' ')
            a--;
         String name = str.substr(a+1,b - a);

         while (str[a] == ' ')
            a--;
         String rtype = str.substr(0,a+1);
         //
         write(file,"GL_FUNCTION("+name+","+rtype+","+args+")\n");
      }
      write(file,"GL_GROUP_END()\n#endif\n");
   }
}
Exemplo n.º 10
0
void PeepsWindow::DeletePerson(PersonData *data)
{
	if(!data)
		return;
	
	PeepsListItem *previtem=NULL, *nextitem=NULL;
	
	for(int32 i=0; i<data->CountGroups();i++)
	{
		PersonItem *pitem=data->InstanceAt(i);
		GroupItem *gitem=(GroupItem*)fPeopleList->Superitem(pitem);

		if(pitem->IsSelected())
		{
			int32 index=fPeopleList->IndexOf(pitem);
			if(index>1)
			{
				previtem=(PeepsListItem*)fPeopleList->ItemAt(index-1);
//				nextitem=(PeepsListItem*)fPeopleList->ItemAt(index+1);
			}
			else
			{
				// First person in the entire list. Check to see if this is the only item in
				// the group. If it is, then select the next item in the list, if it exists.
				if(fPeopleList->CountItemsUnder(gitem,true)==1)
					nextitem=(PeepsListItem*)fPeopleList->ItemAt(index+1);
				else
					previtem=(PeepsListItem*)fPeopleList->ItemAt(index-1);
			}
		}
		fPeopleList->RemoveItem(pitem);
		data->DestroyInstance(pitem);
		if(fPeopleList->CountItemsUnder(gitem,true)==0)
		{
			fPeopleList->RemoveItem(gitem);
			gGroupData.RemoveGroup(gitem->Name());
		}
	}
	entry_ref personref=data->FileRef();
	BEntry entry(&personref);
	if(previtem)
		fPeopleList->Select(fPeopleList->IndexOf(previtem));
	else
	if(nextitem)
		fPeopleList->Select(fPeopleList->IndexOf(nextitem));
	else
		fPeopleList->Select(0L);
#ifndef DATA_READ_ONLY
	TrashFile(&entry);
#endif

	gPeopleData.RemoveItem(data);
	delete data;
}
Exemplo n.º 11
0
bool
COSXKeyState::getGroups(GroupList& groups) const
{
	CFIndex n;
	bool gotLayouts = false;

#if defined(MAC_OS_X_VERSION_10_5)
	// get number of layouts
	CFStringRef keys[] = { kTISPropertyInputSourceCategory };
	CFStringRef values[] = { kTISCategoryKeyboardInputSource };
	CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
	CFArrayRef kbds = TISCreateInputSourceList(dict, false);
	n = CFArrayGetCount(kbds);
	gotLayouts = (n != 0);
#else
	OSStatus status = KLGetKeyboardLayoutCount(&n);
	gotLayouts = (status == noErr);
#endif

	if (!gotLayouts) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}

	// get each layout
	groups.clear();
	for (CFIndex i = 0; i < n; ++i) {
		bool addToGroups = true;
#if defined(MAC_OS_X_VERSION_10_5)
		TISInputSourceRef keyboardLayout = 
			(TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);
#else
		KeyboardLayoutRef keyboardLayout;
		status = KLGetKeyboardLayoutAtIndex(i, &keyboardLayout);
		addToGroups == (status == noErr);
#endif
		if (addToGroups)
    		groups.push_back(keyboardLayout);
	}
	return true;
}
Exemplo n.º 12
0
void PeepsWindow::AddPerson(const entry_ref &ref, bool highlight)
{
	// Check to see if it's actually a Person file
	if(!IsPerson(ref))
		return;
	
	GroupData *gdata;
	
	// Add person to data list
	PersonData *pdata=new PersonData(ref);
	gPeopleData.AddItem(pdata);
	
	// add group(s) and an item for each group
	
	if(strlen(pdata->Group())==0)
	{
		// Ungrouped case
		gdata=gGroupData.AddGroup(TRANSLATE("Ungrouped"));
		if(!fPeopleList->HasItem(gdata->GetInstance()))
			fPeopleList->AddItem(gdata->GetInstance());
		
		gdata->AddPerson(pdata);
		fPeopleList->AddUnder(pdata->CreateInstance(TRANSLATE("Ungrouped")),gdata->GetInstance());
		return;
	}
	
	GroupParser gp(pdata->Group());
	
	for(int32 i=0; i<gp.CountGroups(); i++)
	{
		gdata=gGroupData.AddGroup(gp.GroupAt(i));
		gdata->AddPerson(pdata);
		if(!fPeopleList->HasItem(gdata->GetInstance()))
			fPeopleList->AddItem(gdata->GetInstance());
		fPeopleList->AddUnder(pdata->CreateInstance(gp.GroupAt(i)),gdata->GetInstance());
	}
	if(highlight)
	{
		SelectPerson(pdata->Name());
	}
}
Exemplo n.º 13
0
void ContactsTreeWidget::loadContactList() {
  appInstance->logEvent("ContactsTreeWidget::loadContactList()", SEVERITY_DEBUG);
  GroupList *gl = appInstance->mUser->getGroupList();
  ContactList *cl;
  ContactList::iterator c**t;
  GroupList::iterator glIt;
  appInstance->mainWindow->contactsTree->treeModel->clear();
  for (glIt = gl->begin(); glIt != gl->end(); glIt++) {
    cl = glIt->second.contacts();
    // prevent adding empty "Unauthorized" group
    if(glIt->first != GROUP_INDEX_NOT_AUTHORIZED || !cl->empty()) {
      appInstance->mainWindow->contactsTree->addGroup(glIt->first, glIt->second);
    }
  }
  for (glIt = gl->begin(); glIt != gl->end(); glIt++) {
    cl = glIt->second.contacts();
    for(c**t = cl->begin(); c**t != cl->end(); c**t++) {
      appInstance->mainWindow->contactsTree->addContact(*c**t);
    }
  }
  appInstance->mainWindow->contactsTree->loadAvatars();
}
bool
CMSWindowsKeyState::getGroups(GroupList& groups) const
{
	// get keyboard layouts
	UInt32 newNumLayouts = GetKeyboardLayoutList(0, NULL);
	if (newNumLayouts == 0) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}
	HKL* newLayouts = new HKL[newNumLayouts];
	newNumLayouts = GetKeyboardLayoutList(newNumLayouts, newLayouts);
	if (newNumLayouts == 0) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		delete[] newLayouts;
		return false;
	}

	groups.clear();
	groups.insert(groups.end(), newLayouts, newLayouts + newNumLayouts);
	delete[] newLayouts;
	return true;
}
Exemplo n.º 15
0
void loadDir(GroupList& groups,String name,const char* filter)
{
   DIR *dir = opendir(name);
   if (!dir) {
      Print("Could not open file " + name);
      return;
   }

   struct dirent *fEntry;
   while ((fEntry = readdir(dir)) != 0) {
      if (fEntry->d_name[0] == '.')
         continue;
      String file = name + "/" + String(fEntry->d_name);
      if (filter[0] != '*' && file.find(filter) == String::NPos)
         continue;
      //Print("Loading " + file);
      groups.pushBack(Group());
      if (!loadFile(groups.last(),file))
         groups.popBack();
   }

   quickSort(groups.begin(),groups.end());
}
Exemplo n.º 16
0
void outputHeader(GroupList& groups, String name)
{
   FILE* file = fopen(name.c_str(),"w");
   if (!file)
      Print("Could not open file " + name);

   // Output all the group name together at the top
   for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++)
         write(file,"#define " + grp->name + "\n");

#if 0 // Types now with the group
   // Output all the types for all the extensions
   for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++)
      for (Array<String>::Iterator itr = grp->types.begin();
            itr != grp->types.end(); itr++)
         write(file,*itr + ";\n");
#endif

   // Output the defines for each group
   for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++) {
      if (!grp->name)
         continue;
      write(file,"\n#ifdef " + grp->name + "\n");
      for (Array<String>::Iterator itr = grp->types.begin();
            itr != grp->types.end(); itr++)
         write(file,*itr + ";\n");
      for (Array<String>::Iterator itr = grp->defines.begin();
            itr != grp->defines.end(); itr++) {
         write(file,"#define " + *itr  + "\n");
      }
      for (Array<String>::Iterator itr = grp->functions.begin();
            itr != grp->functions.end(); itr++) {
         String& str = *itr;

         // Parse function "return name (args)".  Start at the back because
         // args is enclosed in (), the name has no spaces, and the return type
         // can be several tokens, such as "void *" or "const char *"
         int b = str.length();
         int a = b - 1;
         while (str[a] != '(')
            a--;
         while (str[--a] == ' ')
            ;
         b = a;
         while (str[a] != ' ')
            a--;
         String name = str.substr(a+1,b - a);

         //
         write(file,"#define "+name+" XGL_FUNCPTR("+name+")\n");
      }
      write(file,"#endif\n");
   }
}
Exemplo n.º 17
0
void cPlayer::ResolveGroups()
{
	// Clear resolved groups first
	m_ResolvedGroups.clear();

	// Get a complete resolved list of all groups the player is in
	std::map< cGroup*, bool > AllGroups;	// Use a map, because it's faster than iterating through a list to find duplicates
	GroupList ToIterate;
	for( GroupList::iterator GroupItr = m_Groups.begin(); GroupItr != m_Groups.end(); ++GroupItr )
	{
		ToIterate.push_back( *GroupItr );
	}
	while( ToIterate.begin() != ToIterate.end() )
	{
		cGroup* CurrentGroup = *ToIterate.begin();
		if( AllGroups.find( CurrentGroup ) != AllGroups.end() )
		{
			LOGWARNING("ERROR: Player \"%s\" is in the group multiple times (\"%s\"). Please fix your settings in users.ini!",
				GetName().c_str(), CurrentGroup->GetName().c_str()
			);
		}
		else
		{
			AllGroups[ CurrentGroup ] = true;
			m_ResolvedGroups.push_back( CurrentGroup );	// Add group to resolved list
			const cGroup::GroupList & Inherits = CurrentGroup->GetInherits();
			for( cGroup::GroupList::const_iterator itr = Inherits.begin(); itr != Inherits.end(); ++itr )
			{
				if( AllGroups.find( *itr ) != AllGroups.end() )
				{
					LOGERROR("ERROR: Player %s is in the same group multiple times due to inheritance (%s). FIX IT!", GetName().c_str(), (*itr)->GetName().c_str() );
					continue;
				}
				ToIterate.push_back( *itr );
			}
		}
		ToIterate.erase( ToIterate.begin() );
	}
}
Exemplo n.º 18
0
bool GroupDef::isASubGroup() const
{
  GroupList *groups = partOfGroups();
  return groups!=0 && groups->count()!=0;
}
Exemplo n.º 19
0
void PeepsWindow::DeleteGroup(GroupItem *item)
{
	// We are going to delete the group. All items will be made ungrouped. Because
	// it cannot be undone, we will ask the user if it's ok to delete the group
	
	BString alertmsg=TRANSLATE("Are you sure you want to delete this group?");
	alertmsg+="\n\n";
	alertmsg+=TRANSLATE("All items will be removed from this group, but the items themselves will not"
		" be deleted. Once done, this cannot be undone.");
	BAlert *alert=new BAlert("Mr. Peeps!", alertmsg.String(), TRANSLATE("Delete Group"), 
		TRANSLATE("Cancel"));
	
	if(alert->Go()==1)
		return;

	if(!item)
		return;
	
	if(!item->IsExpanded())
		fPeopleList->Expand(item);

	// First, ensure that we have a group for all these items to go to
	
	GroupData 	*oldgdata=item->GetData(),
				*ungrouped=gGroupData.FindGroup(TRANSLATE("Ungrouped"));
	
	if(!ungrouped)
	{
		ungrouped=gGroupData.AddGroup(TRANSLATE("Ungrouped"));
		fPeopleList->AddItem(ungrouped->GetInstance());
	}

	if(!ungrouped->GetInstance()->IsExpanded())
		fPeopleList->Expand(ungrouped->GetInstance());

	int32 groupindex=fPeopleList->FullListIndexOf(ungrouped->GetInstance())+1;
	
	// Now, we iterate through each person in the group to remove the group name
	// from their group list strings
	for(int32 i=0; i<oldgdata->CountPeople(); i++)
	{
		PersonData *pdata=oldgdata->PersonAt(i);

		if(pdata->CountGroups()==1)
		{
			pdata->AddToGroup(ungrouped->GetInstance());
			fPeopleList->MoveItem(fPeopleList->FullListIndexOf(pdata->InstanceAt(0)),groupindex);
		}
		else
		{
			PersonItem *instance=pdata->InstanceForGroup(item->Name());
			fPeopleList->RemoveItem(instance);
			pdata->DestroyInstance(instance);
		}
		pdata->RemoveFromGroup((GroupItem*)item);
	}
	
	fPeopleList->RemoveItem((GroupItem*)item);
	gGroupData.RemoveGroup(item->Name());
	fPeopleList->SortItemsUnder(ungrouped->GetInstance(),true,compare_peeps);
	fPeopleList->Select(fPeopleList->IndexOf(ungrouped->GetInstance()));
}
Exemplo n.º 20
0
GroupDef *PageDef::getGroupDef() const 
{ 
  GroupList *groups = partOfGroups();
  return groups!=0 ? groups->getFirst() : 0; 
}
Exemplo n.º 21
0
/*
  This function collect all groups of parameters described in the
  scad file.
*/
static GroupList collectGroups(const std::string &fulltext)
{
	GroupList groupList; // container of all group names
	int lineNo = 1; // tracks line number
	bool inString = false; // check if its string or (line-) comment

	// iterate through whole scad file
	for (unsigned int i=0; i<fulltext.length(); i++) {
		// increase line number
		if (fulltext[i] == '\n') {
			lineNo++;
			continue;
		}

		// skip escaped quotes inside strings
		if (inString && fulltext.compare(i, 2, "\\\"") == 0) {
			i++;
			continue;
		}

		//start or end of string negate the checkpoint
		if (fulltext[i] == '"') {
			inString = !inString;
			continue;
		}

		if (!inString && fulltext.compare(i, 2, "//") == 0) {
			i++;
			while (fulltext[i] != '\n' && i<fulltext.length() ) i++;
			lineNo++;
			continue;
		}

		//start of multi line comment if check is true
		if (!inString && fulltext.compare(i, 2, "/*") == 0) {
			//store comment
			std::string comment;
			i++;
			if(i<fulltext.length()) {
				i++;
			}
			else {
				continue;
			}
			bool isGroup=true;
			// till */ every character is comment
			while (fulltext.compare(i, 2, "*/") != 0 && i<fulltext.length()) {
				if(fulltext[i]=='\n'){
					lineNo++;
					isGroup=false;
				}
				comment += fulltext[i];
				i++;
			}

			if(isGroup)
				groupList.push_back(createGroup(comment,lineNo));
		}
	}
	return groupList;
}
Exemplo n.º 22
0
int main()
{
	// shaders
	ReflectionShader *sdr_white = new ReflectionShader();
	sdr_white->reflect_color(.8, .8, .8);
	sdr_white->glossiness = 0;

	ReflectionShader *sdr_red = new ReflectionShader();
	sdr_red->reflect_color(.8, .2, .1);
	sdr_red->glossiness = 0;
	
	ReflectionShader *sdr_blue = new ReflectionShader();
	sdr_blue->reflect_color(.1, .3, .8);
	sdr_blue->glossiness = 0;
	
	RefractionShader *sdr_glass = new RefractionShader();
	sdr_glass->diffuse_color(.8, .8, .8);
	sdr_glass->specular_color(.8, .8, .8);
	sdr_glass->refract_index = 1.5;

	ReflectionShader *sdr_light = new ReflectionShader();
	sdr_light->reflect_color(.8, .8, .8);
	sdr_light->light_color(1,1,1);
	sdr_light->light_per_area = 5;
	sdr_light->glossiness = 0;

	// create camera
	Camera camera;
	camera.width = 600;
	camera.height = 400;
	camera.subsamples = 10;
	camera.replaceFilm();

	//--------------------------------------------------------------------------------
	// Build the scene
	//--------------------------------------------------------------------------------
	double t_init = get_time();

	// camera
	double angle = 0;
	camera.fov_y = 55;
	camera.orient = Quaternion::makeRotation(-pi/2, 1, 0, 0)*Quaternion::makeRotation(angle, 0, 0, 1);
	camera.pos(2*sin(angle+pi), 2*cos(angle+pi), .5);
	camera.focal_length = 17;
	camera.aperture = 0.0;



	GroupList occluder;

	// room triangles
	Array<Occluder*> splist;
	vect3d verts[4*3];
	double rh = 1;
	double rw = 1;
	double rl = .3;
	verts[0](-rw,-rw,0);
	verts[1](rw,-rw,0);
	verts[2](rw,rw,0);
	verts[3](-rw,rw,0);
	
	verts[4](-rw,-rw,rh);
	verts[5](rw,-rw,rh);
	verts[6](rw,rw,rh);
	verts[7](-rw,rw,rh);
	
	verts[8](-rl,-rl,rh);
	verts[9](rl,-rl,rh);
	verts[10](rl,rl,rh);
	verts[11](-rl,rl,rh);

	splist.push(new Triangle(verts[0], verts[1], verts[2], sdr_white)); // floor
	splist.push(new Triangle(verts[0], verts[2], verts[3], sdr_white));

	splist.push(new Triangle(verts[0], verts[4], verts[5], sdr_white)); // front wall
	splist.push(new Triangle(verts[0], verts[5], verts[1], sdr_white));
	
	splist.push(new Triangle(verts[3], verts[2], verts[6], sdr_white)); // back wall
	splist.push(new Triangle(verts[3], verts[6], verts[7], sdr_white));
	
	splist.push(new Triangle(verts[3], verts[7], verts[4], sdr_red)); // left wall
	splist.push(new Triangle(verts[3], verts[4], verts[0], sdr_red));
	
	splist.push(new Triangle(verts[2], verts[1], verts[5], sdr_blue)); // right wall
	splist.push(new Triangle(verts[2], verts[5], verts[6], sdr_blue));
	
	splist.push(new Triangle(verts[8], verts[11], verts[10], sdr_light)); // light panel
	splist.push(new Triangle(verts[8], verts[10], verts[9], sdr_light));
	
	splist.push(new Triangle(verts[4], verts[8], verts[9], sdr_white)); // ceiling
	splist.push(new Triangle(verts[4], verts[9], verts[5], sdr_white));
	splist.push(new Triangle(verts[7], verts[11], verts[8], sdr_white)); // ceiling
	splist.push(new Triangle(verts[7], verts[8], verts[4], sdr_white));
	splist.push(new Triangle(verts[6], verts[10], verts[11], sdr_white)); // ceiling
	splist.push(new Triangle(verts[6], verts[11], verts[7], sdr_white));
	splist.push(new Triangle(verts[5], verts[9], verts[10], sdr_white)); // ceiling
	splist.push(new Triangle(verts[5], verts[10], verts[6], sdr_white));

	splist.push(new Sphere(vect3d(.25, .25, .25), .25, sdr_white)); // a sphere
	
	splist.push(new Sphere(vect3d(-.25, -.35, .35), .35, sdr_glass)); // a sphere

	occluder.add(new GroupTree(splist, 0));


	// finalize and light the scene
	Scene scene;
	scene.background_color = 0;
	scene.occluder = &occluder;

	Array<Occluder *> lights;
	for (int i = 0; i < splist.size(); i++)
	{
		if (splist[i]->light_power() > 0)
			lights.push(splist[i]);
	}
	scene.build_lights(lights);

	//--------------------------------------------------------------------------------
	// Render the scene
	//--------------------------------------------------------------------------------
	double t_start = get_time();
	printf("Time taken to create scene = %fs\n", (t_start - t_init));

	camera.expose(&scene);

	double t_end = get_time();
	printf("Time taken to render = %fs\n", (t_end - t_start));

	//--------------------------------------------------------------------------------
	// Write the image to disk
	//--------------------------------------------------------------------------------

	fipImage *bmp = camera.create_image();
	bmp->save("output.png");
	delete bmp;

	//--------------------------------------------------------------------------------
	// Free memory for scene
	//--------------------------------------------------------------------------------
	for (int i = 0; i < splist.s; i++)
		delete splist[i];

	for (int i = 0; i < occluder.list.s; i++)
		delete occluder.list[i];

	return 0;
}
Exemplo n.º 23
0
GroupList *load_obj(string fn, Shader *shader)
{
	GroupList *mesh = new GroupList();
	Array<vect3d> verts, norms, texc;

	ifstream reader(fn.c_str());
	assert(!reader.fail()); 

	string whitespace = " \t\n";
	string slash = "/";

	string line;
	while (true)
	{
		line = readline(reader);
		if (reader.eof())
			break;

		Array<string> toks;
		split(line, whitespace, toks);
		if (toks.s == 0)
			continue;

		if (toks[0] == "v")
		{
			verts.push(vect3d(atof(toks[1].c_str()), atof(toks[2].c_str()), atof(toks[3].c_str())));
		}
		else if (toks[0] == "vt")
		{
			texc.push(vect3d(atof(toks[1].c_str()), atof(toks[2].c_str()), 0));
		}
		else if (toks[0] == "vn")
		{
			norms.push(vect3d(atof(toks[1].c_str()), atof(toks[2].c_str()), atof(toks[3].c_str())));
		}
		else if (toks[0] == "f")
		{
			Array<string> vals0, vals1, vals2;
			
			splitEmpty(toks[1], slash, vals0);
			splitEmpty(toks[2], slash, vals1);
			splitEmpty(toks[3], slash, vals2);

			int i0 = atoi(vals0[0].c_str()) - 1;
			int i1 = atoi(vals1[0].c_str()) - 1;
			int i2 = atoi(vals2[0].c_str()) - 1;
			
			if (i0 < 0)
				i0 += verts.s + 1;
			if (i1 < 0)
				i1 += verts.s + 1;
			if (i2 < 0)
				i2 += verts.s + 1;

			Triangle *t = new Triangle(verts[i0], verts[i1], verts[i2], shader);

			if (texc.s != 0)
			{
				int j0 = atoi(vals0[1].c_str()) - 1;
				int j1 = atoi(vals1[1].c_str()) - 1;
				int j2 = atoi(vals2[1].c_str()) - 1;

				t->t0 = texc[j0];
				t->t1 = texc[j1];
				t->t2 = texc[j2];
			}
			if (norms.s != 0)
			{
				int k0 = atoi(vals0[2].c_str()) - 1;
				int k1 = atoi(vals1[2].c_str()) - 1;
				int k2 = atoi(vals2[2].c_str()) - 1;

				t->n0 = norms[k0];
				t->n1 = norms[k1];
				t->n2 = norms[k2];
			}

			mesh->add(t);
		}
	}

	reader.close();

	//// calc center
	//vect3f sum = 0;
	//for (int i = 0; i < verts.s; i++)
	//{
	//	sum += verts[i];
	//}
	//sum /= verts.s;
	//printf("CENTER AT %f, %f, %f\n", sum[0], sum[1], sum[2]);

	//// subtract center
	//for (int i = 0; i < mesh->list.s; i++)
	//{
	//	((Triangle*)mesh->list[i])->p0 -= sum;
	//	((Triangle*)mesh->list[i])->p1 -= sum;
	//	((Triangle*)mesh->list[i])->p2 -= sum;
	//}
	return mesh;
}
Exemplo n.º 24
0
int main()
{
	ifstream file("../resources/spheres.dat");
	if (file.fail())
	{
		printf("FAILED TO OPEN spheres.dat\n");
		return 1;
	}
	mkdir("out");

	// shaders
	ReflectionShader *sdr_plane = new ReflectionShader();
	sdr_plane->specular_color(.5, .5, .8);
	sdr_plane->glossiness = 0;

	ReflectionShader *sdr_big = new ReflectionShader();
	sdr_big->diffuse_color = 0;
	sdr_big->specular_color(.5,.1,.1);
	sdr_big->glossiness = 0;
	
	ReflectionShader *sdr_small = new ReflectionShader();
	sdr_small->diffuse_color = 0;
	sdr_small->specular_color(.5,.5,.1);
	sdr_small->glossiness = 0;
	
	// create camera
	Camera camera;
	camera.width = 1280 / 1;
	camera.height = 720 / 1;
	camera.subsamples = 1;
	camera.replaceFilm();
	
	Array<vect4d> spheres; 

	int render_start = 2239;
	int render_stop = 2400;
	int render_remainder = 0;

	// render frames
	int physframes = 33;
	for (int frame = 0; frame < 2400*physframes; frame++)
	{
		//for (int i = 0; i < frameskip * physframes; i++)
			loadSpheres(file, spheres);
			
		if (frame / physframes > render_stop)
			break;

		if (frame < render_start*physframes || (frame/physframes) % 2 != render_remainder)
		{
			//printf("skipping frame %d\n", frame / physframes);
			continue;
		}

		//--------------------------------------------------------------------------------
		// Build the scene
		//--------------------------------------------------------------------------------
		double t_init = get_time();

		// camera
		double angle = -4*2*pi*frame / double(2400*physframes);
		camera.fov_y = 55;
		camera.orient = Quaternion::makeRotation(-pi/2, 1, 0, 0)*Quaternion::makeRotation(angle, 0, 0, 1);
		camera.pos(20*sin(angle+pi), 20*cos(angle+pi), 5);
		camera.focal_length = 17;
		camera.aperture = 0.3;



		GroupList occluder;

		// ground plane
		{
			Plane *plane = new Plane(vect3d(0, 0, 0), vect3d(1, 0, 0), vect3d(1, 1, 0), sdr_plane);
			plane->x *= .3;
			plane->y *= .3;
			occluder.add(plane);
		}

		// spheres
		Array<Occluder*> splist;

		for (int i = 0; i < spheres.s; i++)
		{
			vect4d &spv = spheres[i];

			ReflectionShader *sdr;
			if (spv[3] >= .99)
				sdr = sdr_big;
			else
				sdr = sdr_small;
			sdr->glossiness = 0;

			splist.push(new Sphere(vect3d(spv), spv[3], sdr));
		}

		occluder.add(new GroupTree(splist, 0));



		Scene scene;
		scene.occluder = &occluder;
		scene.lights.push(new Light(60, vect3d(-4, 8, 8)));
		scene.lights.push(new Light(40, vect3d(1, 15, 10)));

		//--------------------------------------------------------------------------------
		// Render the scene
		//--------------------------------------------------------------------------------
		double t_start = get_time();
		printf("Time taken to create scene = %fs\n", (t_start - t_init));

		camera.expose(&scene);

		double t_end = get_time();
		printf("Time taken to render = %fs\n", (t_end - t_start));

		//--------------------------------------------------------------------------------
		// Write the image to disk
		//--------------------------------------------------------------------------------
		
		if ((frame % physframes) == physframes-1)
		{
			for (int i = 0; i < camera.width*camera.height; i++)
				camera.film.data[i] /= physframes;
	
			fipImage *bmp = camera.create_image();
			camera.replaceFilm();

			char fn[1024];
			sprintf(fn, "out/frame_%04d.png", frame / physframes);
			bmp->save(fn);

			delete bmp;

			printf("wrote frame %d\n", frame / physframes);
		}

		//--------------------------------------------------------------------------------
		// Free memory
		//--------------------------------------------------------------------------------
		for (int i = 0; i < splist.s; i++)
			delete splist[i];

		for (int i = 0; i < occluder.list.s; i++)
			delete occluder.list[i];
	}

	file.close();
	return 0;
}