/******************* * Program Main * *******************/ int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(window_x_pos, window_y_pos); glutInitWindowSize(window_width, window_height); glutCreateWindow("FDTD2d TM-mode (PBO)"); glutDisplayFunc(display); // glutReshapeFunc(resize); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); /* glutMotionFunc(motion); */ glViewport(0, 0, window_width, window_height); atexit(cleanUp); /*** init data ***/ malloc_Initialdata(); setInitialData(grid_width, grid_height); FDTDInit(); PMLInit(); prinfData(); if(!initGL()){ return 1; } glutMainLoop(); return 0; }
//- Construct from Time and timeDict timeFluxData::timeFluxData ( Time& t, const dictionary& timeDict ) : time_(t), writeInterval_(readScalar(t.controlDict().lookup("writeInterval"))), writeIntSteps_(label(writeInterval_/t.deltaT().value() + 0.5)), mdTime_(1, readScalar(time_.controlDict().lookup("deltaT"))), averagingTime_(readLabel(timeDict.lookup("nAverages"))), controlTime_(readLabel(timeDict.lookup("nControls"))), writeTime_(writeIntSteps_, writeInterval_), nAvTimeSteps_("nAvTimeSteps_", dimless, 0.0), nControlSteps_(0.0), totalNAvSteps_(0), totalNContSteps_(0), totalNWrSteps_(0), controlTimeIndex_(0), averagingTimeIndex_(0) // controlTimes_(), // averagingTimes_() { setInitialData(); }
void timeFluxData::setTimeData(const dictionary& timeDict) { const label nAverages(readLabel(timeDict.lookup("nAverages"))); const label nControls(readLabel(timeDict.lookup("nControls"))); averagingTime_.nSteps() = nAverages; controlTime_.nSteps() = nControls; setInitialData(); }
void timeData::setTimeData(const dictionary& timeDict) { const label nSamples(readLabel(timeDict.lookup("nSamples"))); const label nAverages(readLabel(timeDict.lookup("nAverages"))); // const label nCalcProp(readLabel(timeDict.lookup("nCalcProp"))); const label nControls(readLabel(timeDict.lookup("nControls"))); samplingTime_.nSteps() = nSamples; averagingTime_.nSteps() = nAverages; // calcPropTime_.nSteps() = nCalcProp; controlTime_.nSteps() = nControls; setInitialData(); }
//- Construct from Time and timeDict timeData::timeData ( Time& t, const dictionary& timeDict ) : time_(t), timeDict_(timeDict), writeInterval_(readScalar(t.controlDict().lookup("writeInterval"))), writeIntSteps_(label(writeInterval_/t.deltaT().value() +0.5)), resetFieldsAtOutput_(true), resetIndex_(0), mdTime_(1), samplingTime_(readLabel(timeDict.lookup("nSamples"))), averagingTime_(readLabel(timeDict.lookup("nAverages"))), // calcPropTime_(readLabel(timeDict.lookup("nCalcProp"))), controlTime_(readLabel(timeDict.lookup("nControls"))), nAvTimeSteps_("nAvTimeSteps_", dimless, 0.0), nControlSteps_(0.0), totalNSampSteps_(0), totalNAvSteps_(0), totalNContSteps_(0), // totalNCalcSteps_(0), controlTimeIndex_(0), // calcTimeIndex_(0), averagingTimeIndex_(0), decoupledFromWriteInterval_(false) // controlTimes_(), // calcTimes_() // averagingTimes_() { if (timeDict.found("decoupledFromWriteInterval")) { decoupledFromWriteInterval_ = Switch(timeDict.lookup("decoupledFromWriteInterval")); } setInitialData(); }
void Flow::calculateConstraints(const std::shared_ptr<AnimSkeleton>& skeleton, AnimPoseVec& relativePoses, AnimPoseVec& absolutePoses) { cleanUp(); if (!skeleton) { return; } auto flowPrefix = FLOW_JOINT_PREFIX.toUpper(); auto simPrefix = SIM_JOINT_PREFIX.toUpper(); std::vector<int> handsIndices; _groupSettings.clear(); for (int i = 0; i < skeleton->getNumJoints(); i++) { auto name = skeleton->getJointName(i); if (std::find(HAND_COLLISION_JOINTS.begin(), HAND_COLLISION_JOINTS.end(), name) != HAND_COLLISION_JOINTS.end()) { handsIndices.push_back(i); } auto parentIndex = skeleton->getParentIndex(i); if (parentIndex == -1) { continue; } auto jointChildren = skeleton->getChildrenOfJoint(i); // auto childIndex = jointChildren.size() > 0 ? jointChildren[0] : -1; auto group = QStringRef(&name, 0, 3).toString().toUpper(); auto split = name.split("_"); bool isSimJoint = (group == simPrefix); bool isFlowJoint = split.size() > 2 && split[0].toUpper() == flowPrefix; if (isFlowJoint || isSimJoint) { group = ""; if (isSimJoint) { for (int j = 1; j < name.size() - 1; j++) { bool toFloatSuccess; QStringRef(&name, (int)(name.size() - j), 1).toString().toFloat(&toFloatSuccess); if (!toFloatSuccess && (name.size() - j) > (int)simPrefix.size()) { group = QStringRef(&name, (int)simPrefix.size(), (int)(name.size() - j + 1) - (int)simPrefix.size()).toString(); break; } } if (group.isEmpty()) { group = QStringRef(&name, (int)simPrefix.size(), name.size() - (int)simPrefix.size()).toString(); } qCDebug(animation) << "Sim joint added to flow: " << name; } else { group = split[1]; } if (!group.isEmpty()) { _flowJointKeywords.push_back(group); FlowPhysicsSettings jointSettings; if (PRESET_FLOW_DATA.find(group) != PRESET_FLOW_DATA.end()) { jointSettings = PRESET_FLOW_DATA.at(group); } else { jointSettings = DEFAULT_JOINT_SETTINGS; } if (_flowJointData.find(i) == _flowJointData.end()) { auto flowJoint = FlowJoint(i, parentIndex, -1, name, group, jointSettings); _flowJointData.insert(std::pair<int, FlowJoint>(i, flowJoint)); } updateGroupSettings(group, jointSettings); } } else { if (PRESET_COLLISION_DATA.find(name) != PRESET_COLLISION_DATA.end()) { _collisionSystem.addCollisionSphere(i, PRESET_COLLISION_DATA.at(name)); } } } for (auto &jointData : _flowJointData) { int jointIndex = jointData.first; glm::vec3 jointPosition, parentPosition, jointTranslation; glm::quat jointRotation; getJointPositionInWorldFrame(absolutePoses, jointIndex, jointPosition, _entityPosition, _entityRotation); getJointTranslation(relativePoses, jointIndex, jointTranslation); getJointRotation(relativePoses, jointIndex, jointRotation); getJointPositionInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentPosition, _entityPosition, _entityRotation); jointData.second.setInitialData(jointPosition, jointTranslation, jointRotation, parentPosition); } std::vector<int> roots; for (auto &joint :_flowJointData) { if (_flowJointData.find(joint.second.getParentIndex()) == _flowJointData.end()) { joint.second.setAnchored(true); roots.push_back(joint.first); } else { _flowJointData[joint.second.getParentIndex()].setChildIndex(joint.first); } } int extraIndex = -1; for (size_t i = 0; i < roots.size(); i++) { FlowThread thread = FlowThread(roots[i], &_flowJointData); // add threads with at least 2 joints if (thread._joints.size() > 0) { if (thread._joints.size() == 1) { int jointIndex = roots[i]; auto &joint = _flowJointData[jointIndex]; auto &jointPosition = joint.getUpdatedPosition(); auto newSettings = joint.getSettings(); extraIndex = extraIndex > -1 ? extraIndex + 1 : skeleton->getNumJoints(); joint.setChildIndex(extraIndex); auto newJoint = FlowJoint(extraIndex, jointIndex, -1, joint.getName(), joint.getGroup(), newSettings); newJoint.toHelperJoint(jointPosition, HELPER_JOINT_LENGTH); glm::vec3 translation = glm::vec3(0.0f, HELPER_JOINT_LENGTH, 0.0f); newJoint.setInitialData(jointPosition + translation, 100.0f * translation , Quaternions::IDENTITY, jointPosition); _flowJointData.insert(std::pair<int, FlowJoint>(extraIndex, newJoint)); FlowThread newThread = FlowThread(jointIndex, &_flowJointData); if (newThread._joints.size() > 1) { _jointThreads.push_back(newThread); } } else { _jointThreads.push_back(thread); } } } if (_jointThreads.size() == 0) { onCleanup(); } if (handsIndices.size() > 0) { FlowCollisionSettings handSettings; handSettings._radius = HAND_COLLISION_RADIUS; for (size_t i = 0; i < handsIndices.size(); i++) { _collisionSystem.addCollisionSphere(handsIndices[i], handSettings, glm::vec3(), true, true); } } _initialized = _jointThreads.size() > 0; }