blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 2
247
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 4
111
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringlengths 4
58
| visit_date
timestamp[ns]date 2015-07-25 18:16:41
2023-09-06 10:45:08
| revision_date
timestamp[ns]date 1970-01-14 14:03:36
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 1970-01-14 14:03:36
2023-09-06 06:22:19
| github_id
int64 3.89k
689M
⌀ | star_events_count
int64 0
209k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 25
values | gha_event_created_at
timestamp[ns]date 2012-06-07 00:51:45
2023-09-14 21:58:52
⌀ | gha_created_at
timestamp[ns]date 2008-03-27 23:40:48
2023-08-24 19:49:39
⌀ | gha_language
stringclasses 159
values | src_encoding
stringclasses 34
values | language
stringclasses 1
value | is_vendor
bool 1
class | is_generated
bool 2
classes | length_bytes
int64 7
10.5M
| extension
stringclasses 111
values | filename
stringlengths 1
195
| text
stringlengths 7
10.5M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6235367d48e5414b9b90a3fe22501d6384991166
|
2e262663a3c974653ed5f5ca9753edb9ac4f44cd
|
/vector_test.cpp
|
e2e1e07473748b0c9356da99da078decddc0d211
|
[] |
no_license
|
yuzhidi/CppStudy
|
759f782cff831c811737c4eb9d37689572b86daf
|
ab0db9cb7f1cac6dd08426bd83a329d761f08c8a
|
refs/heads/master
| 2021-09-10T04:47:08.193569
| 2018-03-21T02:52:13
| 2018-03-21T02:52:13
| 126,112,703
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 700
|
cpp
|
vector_test.cpp
|
#include <iostream>
#include <vector>
struct LeoStruct {
int i;
std::string s;
LeoStruct(int i, std::string s):i(i),s(s){}
};
int main()
{
// 创建含有整数的 vector
std::vector<int> v = {7, 5, 16, 8};
LeoStruct ls0 = LeoStruct(1, "one");
std::vector<LeoStruct*> lv;
lv.push_back(&ls0);
// 添加二个整数到 vector
v.push_back(25);
v.push_back(13);
// 迭代并打印 vector 的值
for(int n : v) {
std::cout << n << '\n';
}
for(const auto& ls : lv) {
std::cout << ls->s << '\n';
}
ls0.s = "not one";
for(const auto& ls : lv) {
std::cout << "check is not one? : " << ls->s << '\n';
}
}
|
993af0620c2b88e82da4264c2ba5a691ccd14eba
|
cd99ca9461435d1417cb146d966e54272fbcc7ad
|
/3rd party/maxsdk/samples/render/RapidRTRenderer/Translators/BaseTranslator_AMG_to_RTIShader.h
|
22e8f29417779aeeff89538e6fe0069bb18806fd
|
[] |
no_license
|
mortany/xray15
|
eacce7965e785dd71d1877eae25c1f9eff680eec
|
72a13fb24e9b388850bc769427c231da8f599228
|
refs/heads/master
| 2020-08-02T20:45:23.493981
| 2019-10-14T18:48:48
| 2019-10-14T18:48:48
| 211,499,718
| 0
| 0
| null | 2019-09-28T12:50:47
| 2019-09-28T12:50:46
| null |
UTF-8
|
C++
| false
| false
| 1,352
|
h
|
BaseTranslator_AMG_to_RTIShader.h
|
//////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "BaseTranslator_to_RTIShader.h"
namespace Max
{;
namespace RapidRTTranslator
{;
// Translates AMG-supporting MtlBase ==> rti::Shader
class BaseTranslator_AMG_to_RTIShader :
public BaseTranslator_to_RTIShader
{
public:
BaseTranslator_AMG_to_RTIShader(TranslatorGraphNode& tanslator_graph_node);
protected:
static bool AMG_IsCompatible(MtlBase *mtlbase);
TranslationResult AMG_Translate(MtlBase *mtlbase, const TimeValue t, Interval& validity, ITranslationProgress& translation_progress,
int dirlights=0, std::vector<rti::Vec4f> *direction_spread = nullptr, std::vector<rti::Vec4f> *color_visi = nullptr);
virtual void report_shader_param_error(const char* param_name) const;
private:
size_t m_lastGraphHash;
};
}} // namespace
#include "BaseTranslator_to_RTIShader.inline.h"
|
a05096c0dfb33722b99dea30027c1d54b1099f3a
|
eb5cc826628b9601542337883dd4f645a32a1535
|
/Training Qt/reseau.cpp
|
1cbd097dbaa670a58a6b318ce95911be82a14971
|
[] |
no_license
|
TenKaiMass/Projet-reseau-de-neurones
|
904bd3fab0e65dd597da5ab49d1238a754752fa5
|
6461e2827a4fa819d755ca90b963098567413bc3
|
refs/heads/master
| 2023-05-15T08:09:26.011404
| 2021-06-25T13:47:44
| 2021-06-25T13:47:44
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 7,594
|
cpp
|
reseau.cpp
|
#include <eigen3/Eigen/Dense>
#include "reseau.hpp"
#include "couche.hpp"
#include "gestionnaireMemoire.hpp"
#include "MainWindow.hpp"
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
using namespace Eigen;
using namespace std;
Reseau::Reseau(Parametres p)
{
typeSim = p.typeSim;
nbCouches = p.nbCouches;
tauxApprentissage = p.tauxApprentissage;
vCouches.reserve(nbCouches);
//Couche d'entrée
if (nbCouches == 2)
vCouches.emplace_back(Couche(p.nbNeuronesEntree, aleaPoids(p.nbNeuronesSortie, p.nbNeuronesEntree), aleaBiais(p.nbNeuronesEntree)));
else
vCouches.emplace_back(Couche(p.nbNeuronesEntree, aleaPoids(p.nbNeuronesCache, p.nbNeuronesEntree), aleaBiais(p.nbNeuronesEntree))); //Couches cachées-1
for (int i = 1; i < (nbCouches - 2); i++)
vCouches.emplace_back(Couche(p.nbNeuronesCache, aleaPoids(p.nbNeuronesCache, p.nbNeuronesCache), aleaBiais(p.nbNeuronesCache)));
//Couche cachée; avant-dernière
int i = 1; //ajout
if (nbCouches > 2)
vCouches.emplace_back(Couche(p.nbNeuronesCache, aleaPoids(p.nbNeuronesSortie, p.nbNeuronesCache), aleaBiais(p.nbNeuronesCache)));
//Couche de sortie
vCouches.emplace_back(Couche(p.nbNeuronesSortie, aleaBiais(p.nbNeuronesSortie)));
}
Reseau::Reseau(Parametres p, vector<MatrixXd> mPoids, vector<VectorXd> vBiais)
{
typeSim = p.typeSim;
nbCouches = p.nbCouches;
tauxApprentissage = p.tauxApprentissage;
vCouches.reserve(nbCouches);
//Couche d'entrée
vCouches.emplace_back(Couche(p.nbNeuronesEntree, mPoids[0], vBiais[0]));
//Couches cachées-1
for (int i = 1; i < (nbCouches - 2); i++)
{
vCouches.emplace_back(Couche(p.nbNeuronesCache, mPoids[i], vBiais[i]));
}
//Couche cachée; avant-dernière
if (nbCouches > 2)
vCouches.emplace_back(Couche(p.nbNeuronesCache, mPoids[nbCouches - 2], vBiais[nbCouches - 2]));
//Couche de sortie
vCouches.emplace_back(Couche(p.nbNeuronesSortie, vBiais[nbCouches - 1]));
}
//Destructeur
Reseau::~Reseau() {}
//Getteurs
unsigned int Reseau::getNbCouches() { return nbCouches; };
vector<MatrixXd> Reseau::getPoids()
{
vector<MatrixXd> poids;
poids.resize(nbCouches); //mettre taille au vec
for (int i = 0; i < nbCouches; i++)
{
poids.push_back(vCouches[i].mPoids);
}
return poids;
};
vector<unsigned int> Reseau::getStats() { return stats; }
//Méthodes du RNU
int Reseau::max(VectorXd sorties) //permet d'avoir l'indice de la valeur max
{
int max = 0;
int indice = -1;
for (int i = 0; i < (sorties.size()); i++)
{
if (max < sorties[i])
{
max = sorties[i];
indice = i;
}
}
return indice;
}
void Reseau::printReseau()
{
for (int i = 0; i < nbCouches; i++)
{
std::cout << "Matrice " << i << " :\n"
<< vCouches[i].mPoids << std::endl
<< std::endl;
}
for (int i = 0; i < nbCouches; i++)
{
std::cout << "Vecteur " << i << " :\n"
<< vCouches[i].vBiais << std::endl
<< std::endl;
}
}
int Reseau::simulation(VectorXd entrees) /*applique la propa + max */
{
VectorXd v;
v = propagation(entrees);
return max(v);
}
VectorXd sigmoide(VectorXd entree) //apparently slow
{
VectorXd sortie(entree.size());
for (int i = 0; i < entree.size(); i++)
{
double dividend = exp(-entree[i]);
dividend += 1;
sortie[i] = 1 / dividend;
}
return sortie;
}
double fast_sigmoide(double entree)
{
double sortie;
double diviseur = abs(entree);
diviseur += 1;
sortie = 1 / diviseur;
return sortie;
}
double Reseau::deriveeSigmoide(double sigmo)
{
double sortie;
sortie = 1 - sigmo;
sortie *= sigmo;
return sigmo;
}
VectorXd Reseau::propagation(VectorXd entrees)
{
MatrixXd mult;
vCouches[0].vActivation = sigmoide(entrees + vCouches[0].vBiais); //modify the activation vector
for (int i = 1; i < nbCouches; i++) //boucle pour TOUTES les couches cachees
{
mult = vCouches[i - 1].mPoids * vCouches[i - 1].vActivation;
for (int n = 0; n < vCouches[i].nbNeurones; n++)
{
vCouches[i].vActivation = sigmoide(mult + vCouches[i].vBiais); //modify the activation vector
}
}
return vCouches[nbCouches - 1].vActivation; //retourne le calcul sigmoide de la derniere couche
}
// calcul delta1
VectorXd Reseau::calculDelta1(VectorXd resultatAttendu)
{
VectorXd error = resultatAttendu - vCouches[nbCouches - 1].vActivation;
return error;
}
MatrixXd Reseau::calculDelta2(VectorXd delta, MatrixXd poids)
{
int nbNeuronesMax = vCouches[0].nbNeurones;
nbNeuronesMax = (vCouches[1].nbNeurones > nbNeuronesMax) ? vCouches[1].nbNeurones : (vCouches[nbCouches - 1].nbNeurones > nbNeuronesMax ? vCouches[nbCouches - 1].nbNeurones : nbNeuronesMax);
MatrixXd deltaMatrice(nbCouches, nbNeuronesMax); // matrice d'erreur
//vector<VectorXd> deltaMatrice;
//deltaMatrice.
// copier le vecteur delta du calcul delta1
deltaMatrice.row(nbCouches - 1) = delta; //on colle delta dans la derniere colonne
cout << "On a copie la colonnnnnne !\n";
for (int boucle = nbCouches - 2; boucle >= 0; boucle++)
{
VectorXd mult;
// calcul somme
for (int i = 0; i < nbCouches; i++) //boucle pour TOUTES les couches cachees
{
mult += vCouches[i - 1].mPoids * vCouches[i - 1].vActivation;
}
for (int j = nbCouches - 2; j >= 0; j--)
{
for (int i = 0; i < vCouches[i].nbNeurones; i++)
{
deltaMatrice(j, i) = ((deriveeSigmoide(vCouches[j].vActivation[i])) * deltaMatrice(j, i - 1) * mult[i]);
}
}
}
return deltaMatrice;
}
void Reseau::miseAJour(MatrixXd delta, VectorXd activation)
{
int indexDerniereCouche;
int nbNeuronesCouche;
double gradient;
for (int j = 0; j < nbCouches; j++)
{
for (int i = 0; i < vCouches[i].nbNeurones; i++)
{
gradient = tauxApprentissage * vCouches[j].vActivation[i - 1] * delta(i, j);
vCouches[j].mPoids(i, j) = vCouches[j].mPoids(i, j) + gradient;
vCouches[j].vBiais(i) = vCouches[j].vBiais(i) + gradient;
}
}
}
bool Reseau::retropropagation(VectorXd entree, VectorXd resultatAttendu)
{
// propagation
VectorXd propa;
propa = propagation(entree);
VectorXd delta = calculDelta1(resultatAttendu);
cout << "Delta 1 fonctionne :\n"
<< delta << endl
<< endl;
// récupération du resultatattendu
if (max(delta) == max(resultatAttendu))
{
cout << "Verification Delta" << endl;
// calculdelta2
MatrixXd d2;
for (int i = nbCouches - 1; i >= 0; i++)
{
d2 = calculDelta2(delta, vCouches[i].mPoids);
cout << "Delta 2 num " << i << " : " << d2 << endl;
// miseàjour
miseAJour(d2, vCouches[i].vActivation);
}
return false;
}
else
{
cout << "On est pas passe par Mise a Jour\n";
return true;
}
}
VectorXd Reseau::retourLabel(int label)
{
// récupération du resultat attendu
VectorXd repAttendues;
if (typeSim == 1) // bmp chien chat
repAttendues.Zero(2);
else if (typeSim == 2) //chiffres
repAttendues.Zero(10);
else if (typeSim == 3) //lettres
repAttendues.Zero(26);
repAttendues[label] = 1;
return repAttendues;
}
vector<VectorXd> Reseau::allLabels(vector<int> labels)
{
vector<VectorXd> vReponses;
for (int i = 0; i < labels.size(); i++)
{
vReponses[i] = retourLabel(labels[i]);
}
return vReponses;
}
void Reseau::entrainement(vector<VectorXd> setFichiers, vector<int> labels)
{
bool verifRetro = false;
while(setFichiers.size()) //TOUS les fichiers
{
VectorXd image = setFichiers.back();
VectorXd label = retourLabel(labels.back());
setFichiers.pop_back(); labels.pop_back();
unsigned int tauxEchec = -1;
while(!verifRetro)
{
verifRetro = this->retropropagation(image, label);
tauxEchec++;
}
stats.push_back(tauxEchec);
}
}
|
f31a6b77f2968065c9423f873acedd26a241f768
|
4c52be4df12bd8beb241fd9823cdd69d7fb3a70c
|
/QUEIS.cpp
|
08f774cffd468cb745324758955d2fdb3e8d378d
|
[] |
no_license
|
superfanc/cppstack
|
1355ed9cc6ab11b5ff378b2e73f20e0bb259240f
|
084ea049c31cce781d9842e3b637a20a6d5fa0b6
|
refs/heads/master
| 2021-01-12T17:27:06.496922
| 2016-10-21T14:40:03
| 2016-10-21T14:40:03
| 71,567,070
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 912
|
cpp
|
QUEIS.cpp
|
//
// QUEIS.cpp
// Stack
//
// Created by fanaticheng on 2016/10/21.
// Copyright © 2016年 fanaticheng. All rights reserved.
//
#include "QUEIS.hpp"
QUEIS::QUEIS(int m):STACK(m),s(m){ }
QUEIS::QUEIS(const QUEIS &q):STACK(q),s(q.s){ }
QUEIS::operator int() const{
return STACK::operator int();
}
QUEIS& QUEIS::operator<<(int e){
STACK::operator<<(e);
return *this;
}
QUEIS& QUEIS::operator>>(int &e){
int m;
if(s==0){
while(STACK::operator int()!=0){
STACK::operator>>(m);
s<<(m);
}
}
if(s==0)
std::cout<<"该队列为空队列"<<std::endl;
else
s>>(e);
while(s!=0){
s>>(m);
STACK::operator<<(m);
}
return *this;
}
QUEIS& QUEIS::operator=(const QUEIS &q){
QUEIS::~QUEIS();
new (this)QUEIS(q);
return *this;
}
void QUEIS::print( ) const{
STACK::print();
}
QUEIS::~QUEIS(){ }
|
834f41e9b2f72ff1858215a26c44984c731932a5
|
dac5254630fefae851da7c843dcab7f6a6af9703
|
/MacOS/Sources/Plugins/General/CPluginRegisterDialog.cp
|
dcc6c0b1088381ebf23a73a0bf582666d311cc2c
|
[
"Apache-2.0"
] |
permissive
|
gpreviato/Mulberry-Mail
|
dd4e3618468fff36361bd2aeb0a725593faa0f8d
|
ce5c56ca7044e5ea290af8d3d2124c1d06f36f3a
|
refs/heads/master
| 2021-01-20T03:31:39.515653
| 2017-09-21T13:09:55
| 2017-09-21T13:09:55
| 18,178,314
| 5
| 2
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,963
|
cp
|
CPluginRegisterDialog.cp
|
/*
Copyright (c) 2007 Cyrus Daboo. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Source for CPluginRegisterDialog class
#include "CPluginRegisterDialog.h"
#include "CAboutPluginsDialog.h"
#include "CTextFieldX.h"
#include "CUtils.h"
#include "CXStringResources.h"
#include <LPushButton.h>
// __________________________________________________________________________________________________
// C L A S S __ C C R E A T E M A I L B O X D I A L O G
// __________________________________________________________________________________________________
// C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S
// Default constructor
CPluginRegisterDialog::CPluginRegisterDialog()
{
}
// Constructor from stream
CPluginRegisterDialog::CPluginRegisterDialog(LStream *inStream)
: LDialogBox(inStream)
{
}
// Default destructor
CPluginRegisterDialog::~CPluginRegisterDialog()
{
}
// O T H E R M E T H O D S ____________________________________________________________________________
// Get details of sub-panes
void CPluginRegisterDialog::FinishCreateSelf(void)
{
// Do inherited
LDialogBox::FinishCreateSelf();
// Get items
mName = (CTextFieldX*) FindPaneByID(paneid_PluginRegisterName);
mVersion = (CTextFieldX*) FindPaneByID(paneid_PluginRegisterVersion);
mType = (CTextFieldX*) FindPaneByID(paneid_PluginRegisterType);
mManufacturer = (CTextFieldX*) FindPaneByID(paneid_PluginRegisterManufacturer);
mDescription = (CTextFieldX*) FindPaneByID(paneid_PluginRegisterDescription);
mRegKey = (CTextFieldX*) FindPaneByID(paneid_PluginRegisterRegKey);
mRunDemoBtn = (LPushButton*) FindPaneByID(paneid_PluginRegisterRunDemoBtn);
mRemovePluginBtn = (LPushButton*) FindPaneByID(paneid_PluginRegisterRemovePluginBtn);
mCancelBtn = (LPushButton*) FindPaneByID(paneid_PluginRegisterCancelBtn);
}
void CPluginRegisterDialog::SetPlugin(const CPlugin& plugin, bool allow_demo, bool allow_delete)
{
mName->SetText(plugin.GetName());
mVersion->SetText(::GetVersionText(plugin.GetVersion()));
mType->SetText(rsrc::GetIndexedString("Alerts::Plugins::Type", plugin.GetType()));
mManufacturer->SetText(plugin.GetManufacturer());
mDescription->SetText(plugin.GetDescription());
if (!allow_demo)
mRunDemoBtn->Hide();
if (allow_delete)
mCancelBtn->Hide();
else
mRemovePluginBtn->Hide();
}
cdstring CPluginRegisterDialog::GetRegKey(void) const
{
return mRegKey->GetText();
}
|
a19d9dee53f0b6ff7b7b2d375f8e2df65796294f
|
3efc50ba20499cc9948473ee9ed2ccfce257d79a
|
/data/code-jam/files/635101_Frank_563117_1_extracted_A.cpp
|
9fc210fe80b42bc116f7b9bceb69d0489bd41f8e
|
[] |
no_license
|
arthurherbout/crypto_code_detection
|
7e10ed03238278690d2d9acaa90fab73e52bab86
|
3c9ff8a4b2e4d341a069956a6259bf9f731adfc0
|
refs/heads/master
| 2020-07-29T15:34:31.380731
| 2019-12-20T13:52:39
| 2019-12-20T13:52:39
| 209,857,592
| 9
| 4
| null | 2019-12-20T13:52:42
| 2019-09-20T18:35:35
|
C
|
UTF-8
|
C++
| false
| false
| 1,348
|
cpp
|
635101_Frank_563117_1_extracted_A.cpp
|
#include<stdio.h>
#include<vector>
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
#define MAX 110
vector<string> root[10000];
int n, m;
void readin()
{
char in[MAX], *p;
root[0].clear();
scanf("%d %d\n", &n, &m);
for(int i = 1; i <= n+m; i++)
{
root[i].clear();
gets(in);
p = strtok(in, "/");
while(p)
{
string s;
s.append(p);
root[i].push_back(s);
p = strtok(NULL, "/");
}
}
n++;
}
int cmp(int p, int q)
{
int i;
if(root[p].size() < root[q].size())
{
for(i = 0 ; i < root[p].size(); i++)
if(root[p][i].compare(root[q][i]) != 0) break;
}
else
{
for(i = 0 ; i < root[q].size(); i++)
if(root[p][i].compare(root[q][i]) != 0) break;
}
return root[p].size() - i;
}
void solve()
{
int tmp, c, ans = 0, pt = 0;
for(int i = n; i < n+m; i++, pt++)
{
c = 100000;
for(int j = 0; j < n+pt; j++)
{
tmp = cmp(i, j);
if(tmp < c) c = tmp;
}
ans+=c;
}
printf("%d\n", ans);
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("data.txt","r",stdin);
freopen("A-large.in","r",stdin);
freopen("A-large.out","w",stdout);
#endif
int cases;
scanf("%d\n", &cases);
for(int i = 1; i <= cases; i++)
{
printf("Case #%d: ", i);
readin();
solve();
}
return 0;
}
|
301ce606950fe468faa63b5f35b0b6effad0dbb9
|
e8bdcb97aab89e1bf86c4a318d59fe0de1136f27
|
/llama/include/llama/loaders/ll_load_utils.h
|
2efd5b638df817173358d14bde6e3de7051f4468
|
[
"BSD-3-Clause"
] |
permissive
|
biqar/llama-fork
|
97e071d8e8d94cdf1a20ae8fe494787dd4e64e02
|
039c31291496dff0a9a79391ce6eb9cdfaf4d306
|
refs/heads/master
| 2023-07-07T04:05:50.204444
| 2020-10-19T04:35:02
| 2020-10-19T04:35:02
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 37,432
|
h
|
ll_load_utils.h
|
/*
* ll_load_utils.h
* LLAMA Graph Analytics
*
* Copyright 2014
* The President and Fellows of Harvard College.
*
* Copyright 2014
* Oracle Labs.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef LL_LOAD_UTILS_H_
#define LL_LOAD_UTILS_H_
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <string>
#include <vector>
#include "llama/ll_config.h"
#include "llama/ll_streaming.h"
#include "llama/ll_external_sort.h"
#include "llama/loaders/ll_load_async_writable.h"
// High-level configuration
//#define LL_LOAD_CREATE_REV_EDGE_MAP
/**
* A stateless file loader prototype
*/
class ll_file_loader {
public:
/**
* Create a new instance of ll_file_loader
*/
ll_file_loader() {}
/**
* Destroy the instance
*/
virtual ~ll_file_loader() {}
/**
* Determine if this file can be opened by this loader
*
* @param file the file
* @return true if it can be opened
*/
virtual bool accepts(const char* file) = 0;
/**
* Load directly into the read-only representation by creating a new
* level
*
* @param graph the graph
* @param file the file
* @param config the loader configuration
*/
virtual void load_direct(ll_mlcsr_ro_graph* graph, const char* file,
const ll_loader_config* config) = 0;
/**
* Load directly into the read-only representation by creating a new
* level
*
* @param graph the graph
* @param file the file
* @param config the loader configuration
*/
virtual void load_direct(ll_writable_graph* graph, const char* file,
const ll_loader_config* config) {
graph->checkpoint(config);
load_direct(&graph->ro_graph(), file, config);
graph->callback_ro_changed();
}
/**
* Load incrementally into the writable representation
*
* @param graph the graph
* @param file the file
* @param config the loader configuration
*/
virtual void load_incremental(ll_writable_graph* graph, const char* file,
const ll_loader_config* config) = 0;
/**
* Create a data source object for the given file
*
* @param file the file
* @return the data source
*/
virtual ll_data_source* create_data_source(const char* file) = 0;
};
/**
* A generic edge-list loader
*/
template <typename NodeType, bool HasWeight=false,
typename WeightType=float, int WeightTypeCode=LL_T_FLOAT>
class ll_edge_list_loader : public ll_data_source {
/**
* Item format for external sort - for out-edges
*/
struct xs_edge {
NodeType tail;
NodeType head;
};
/**
* Comparator for xs_edge
*/
struct xs_edge_comparator {
bool operator() (const xs_edge& a, const xs_edge& b) {
if (a.tail != b.tail)
return a.tail < b.tail;
else
return a.head < b.head;
}
};
/**
* Item format for external sort - for out-edges
*/
struct xs_w_edge {
NodeType tail;
NodeType head;
WeightType weight;
};
/**
* Comparator for xs_w_edge
*/
struct xs_w_edge_comparator {
bool operator() (const xs_w_edge& a, const xs_w_edge& b) {
if (a.tail != b.tail)
return a.tail < b.tail;
else
return a.head < b.head;
}
};
/**
* Item format for external sort - for in-edges
*/
struct xs_in_edge {
NodeType tail;
NodeType head;
#ifdef LL_LOAD_CREATE_REV_EDGE_MAP
edge_t out_edge;
#endif
};
/**
* Comparator for xs_in_edge
*/
struct xs_in_edge_comparator {
bool operator() (const xs_in_edge& a, const xs_in_edge& b) {
if (a.head != b.head)
return a.head < b.head;
else
return a.tail < b.tail;
}
};
private:
/// True if the data file has still potentially more data left in it
volatile bool _has_more;
/// The last value of _has_more
volatile bool _last_has_more;
public:
/**
* Create an instance of class ll_edge_list_loader
*/
ll_edge_list_loader() {
_has_more = true;
_last_has_more = _has_more;
}
/**
* Destroy the loader
*/
virtual ~ll_edge_list_loader() {
}
protected:
/**
* Read the next edge
*
* @param o_tail the output for tail
* @param o_head the output for head
* @param o_weight the output for weight (ignore if HasWeight is false)
* @return true if the edge was loaded, false if EOF or error
*/
virtual bool next_edge(NodeType* o_tail, NodeType* o_head,
WeightType* o_weight) = 0;
/**
* Rewind the input file
*/
virtual void rewind() = 0;
/**
* Get graph stats if they are available
*
* @param o_nodes the output for the number of nodes (1 + max node ID)
* @param o_edges the output for the number of edges
* @return true if succeeded, or false if not or the info is not available
*/
virtual bool stat(size_t* o_nodes, size_t* o_edges) {
return false;
}
public:
/**
* Return true if the data file has potentially more data in it
*
* @return true if it has more data left
*/
virtual bool has_more() {
return _has_more;
}
/**
* Load the graph directly into the read-only representation
*
* @param graph the graph
* @param config the loader configuration
* @return true on no error
*/
bool load_direct(ll_mlcsr_ro_graph* graph,
const ll_loader_config* config) {
#ifdef LL_S_WEIGHTS_INSTEAD_OF_DUPLICATE_EDGES
LL_E_PRINT("LL_S_WEIGHTS_INSTEAD_OF_DUPLICATE_EDGES not supported");
abort();
#endif
// Check if we have stat and if we can load the data just using the
// info stat gives us.
// Specifically, we need to be able to get a reasonable estimate of the
// max size of the edge table, which gets tricky on levels > 0 when
// copying adjacency lists or deleting using continuations. Loading
// levels > 0 with continuations should work, but it will result in
// reserving space for all continuations, which will be a big waste of
// space in many (most?) cases, so disable it for now (we should
// reenable it when we implement variable-sized edge tables or shrinking
// of edge tables).
// TODO Avoid calling stat twice
size_t new_level = graph->num_levels();
size_t max_nodes = 0;
size_t max_edges = 0;
if (IF_LL_MLCSR_CONTINUATIONS(new_level == 0 &&)
stat(&max_nodes, &max_edges)) {
return load_direct_with_stat(graph, config);
}
LL_D_PRINT("Load without stat, level=%lu\n", new_level);
// Check features
feature_vector_t features;
features << LL_L_FEATURE(lc_direction);
features << LL_L_FEATURE(lc_reverse_edges);
features << LL_L_FEATURE(lc_deduplicate);
features << LL_L_FEATURE(lc_no_properties);
config->assert_features(false /*direct*/, true /*error*/, features);
// Initialize
bool print_progress = config->lc_print_progress;
bool reverse = config->lc_reverse_edges;
bool load_weight = !config->lc_no_properties;
xs_w_edge e;
if (new_level > 0) {
if (max_nodes < (size_t) graph->out().max_nodes()) {
max_nodes = graph->out().max_nodes();
}
}
// Initialize external sort
ll_external_sort<xs_w_edge, xs_w_edge_comparator>* out_sort = NULL;
// Get the degrees
size_t degrees_capacity = 80 * 1000ul * 1000ul;
degree_t* degrees_out = NULL;
degree_t* degrees_in = NULL;
degrees_out = (degree_t*) malloc(sizeof(*degrees_out)*degrees_capacity);
memset(degrees_out, 0, sizeof(*degrees_out) * degrees_capacity);
if (reverse) {
degrees_in = (degree_t*) malloc(
sizeof(*degrees_in) * degrees_capacity);
memset(degrees_in, 0, sizeof(*degrees_in) * degrees_capacity);
}
/*
* PASS 1
* - Determine the node degrees
* - Feed the edges to the external sort (if not already sorted)
*/
NodeType last_tail = 0;
NodeType last_head = 0;
bool already_sorted = true;
bool out_called_sort = false;
if (config->lc_direction == LL_L_UNDIRECTED_DOUBLE) {
already_sorted = false;
out_sort = new ll_external_sort<xs_w_edge,
xs_w_edge_comparator>(config);
}
size_t step = 10 * 1000 * 1000ul;
if (print_progress) {
fprintf(stderr, "[<]");
}
// XXX This split should be done instead if
// config->lc_direction == LL_L_UNDIRECTED_DOUBLE,
// since that's guaranteed to mess up the sort order,
// while config->lc_deduplicate does not necessarily
// mess up things
if (config->lc_deduplicate) {
if (already_sorted) {
already_sorted = false;
out_sort = new ll_external_sort<xs_w_edge,
xs_w_edge_comparator>(config);
}
while (next_edge(&e.tail, &e.head, &e.weight)) {
max_edges++;
if (config->lc_direction == LL_L_UNDIRECTED_ORDERED) {
if (e.tail > e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
}
}
if (last_head == e.head && last_tail == e.tail) {
continue;
}
last_head = e.head;
last_tail = e.tail;
if (e.tail >= (NodeType) max_nodes) max_nodes = e.tail + 1;
if (e.head >= (NodeType) max_nodes) max_nodes = e.head + 1;
*out_sort << e;
if (config->lc_direction == LL_L_UNDIRECTED_DOUBLE) {
if (e.tail != e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
*out_sort << e;
max_edges++;
}
}
if (print_progress) {
if (max_edges % step == 0) {
fprintf(stderr, ".");
if (max_edges % (step * 10) == 0) {
fprintf(stderr, "%lu", max_edges / 1000000ul);
}
}
}
}
if (max_nodes > degrees_capacity) {
size_t d = max_nodes;
degree_t* x = (degree_t*) realloc(degrees_out,
sizeof(*degrees_out)*d);
memset(&x[degrees_capacity], 0,
sizeof(*x)*(d-degrees_capacity));
degrees_out = x;
if (reverse) {
x = (degree_t*) realloc(degrees_in, sizeof(*degrees_in)*d);
memset(&x[degrees_capacity], 0,
sizeof(*x)*(d-degrees_capacity));
degrees_in = x;
}
degrees_capacity = d;
}
out_sort->sort();
out_called_sort = true;
xs_w_edge* buffer;
size_t length;
size_t index = 0;
last_tail = LL_NIL_NODE;
last_head = LL_NIL_NODE;
if (print_progress) {
fprintf(stderr, "[+]");
}
while (out_sort->next_block(&buffer, &length)) {
while (length --> 0) {
if (last_head == buffer->head
&& last_tail == buffer->tail) {
buffer++;
continue;
}
last_head = buffer->head;
last_tail = buffer->tail;
degrees_out[buffer->tail]++;
if (reverse) degrees_in[buffer->head]++;
buffer++;
index++;
if (print_progress) {
if (index % step == 0) {
fprintf(stderr, ".");
if (index % (step * 10) == 0) {
fprintf(stderr, "%lu", index / 1000000ul);
}
}
}
}
}
}
else /* if (!config->lc_deduplicate) */ {
size_t loaded_edges = 0;
while (next_edge(&e.tail, &e.head, &e.weight)) {
max_edges++;
loaded_edges++;
if (config->lc_direction == LL_L_UNDIRECTED_ORDERED) {
if (e.tail > e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
}
}
if (already_sorted) {
if (last_tail > e.tail
|| (last_tail == e.tail && last_head > e.head)) {
already_sorted = false;
loaded_edges = 0;
rewind();
max_edges = 0;
memset(degrees_out, 0, sizeof(*degrees_out)
* degrees_capacity);
if (reverse) {
memset(degrees_in, 0, sizeof(*degrees_in)
* degrees_capacity);
}
out_sort = new ll_external_sort<xs_w_edge,
xs_w_edge_comparator>(config);
continue;
}
}
last_head = e.head;
last_tail = e.tail;
if (e.tail >= (NodeType) max_nodes) max_nodes = e.tail + 1;
if (e.head >= (NodeType) max_nodes) max_nodes = e.head + 1;
if (max_nodes > degrees_capacity) {
size_t d = degrees_capacity;
while (d < max_nodes + 16) d *= 2;
degree_t* x = (degree_t*) realloc(degrees_out,
sizeof(*degrees_out)*d);
memset(&x[degrees_capacity], 0,
sizeof(*x)*(d-degrees_capacity));
degrees_out = x;
if (reverse) {
x = (degree_t*) realloc(degrees_in,
sizeof(*degrees_in)*d);
memset(&x[degrees_capacity], 0,
sizeof(*x)*(d-degrees_capacity));
degrees_in = x;
}
degrees_capacity = d;
}
degrees_out[e.tail]++;
if (reverse) degrees_in[e.head]++;
if (!already_sorted) {
*out_sort << e;
}
if (config->lc_direction == LL_L_UNDIRECTED_DOUBLE) {
if (e.tail != e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
max_edges++;
degrees_out[e.tail]++;
if (reverse) degrees_in[e.head]++;
if (!already_sorted) {
*out_sort << e;
}
}
}
if (print_progress) {
if (loaded_edges % step == 0) {
fprintf(stderr, ".");
if (loaded_edges % (step * 10) == 0) {
fprintf(stderr, "%lu", loaded_edges / 1000000ul);
}
}
}
} /* Ends: while(...) { ... } */
} /* Ends: if (config->lc_deduplicate) { ... } else { ... } */
/*
* PASS 2
* - Write out the level, either by re-reading the input file if it
* is sorted or by pulling them out of external sort
* - Feed the edges into the in-edges external sort
*/
// Create the out-edges level
auto& out = graph->out();
out.init_level_from_degrees(max_nodes, degrees_out, NULL);
LL_ET<node_t>* et = graph->out().edge_table(new_level);
auto* vt = out.vertex_table(new_level); (void) vt;
// If the out-to-in, in-to-out properties are not enabled, disable
// that feature in the corresponding ll_csr_base
if (!config->lc_reverse_edges || !config->lc_reverse_maps) {
graph->out().set_edge_translation(false);
graph->in().set_edge_translation(false);
}
// Initialize the weight property
ll_mlcsr_edge_property<WeightType>* prop_weight = NULL;
if (load_weight) prop_weight = init_prop_weight(graph);
// Initialize the external sort for the in-edges
ll_external_sort<xs_in_edge, xs_in_edge_comparator>* in_sort = NULL;
if (reverse) {
in_sort = new ll_external_sort<xs_in_edge,
xs_in_edge_comparator>(config);
}
// Write the out-edges
if (print_progress) {
fprintf(stderr, "[O]");
}
if (already_sorted) {
assert(config->lc_direction != LL_L_UNDIRECTED_DOUBLE);
rewind();
last_head = LL_NIL_NODE;
last_tail = LL_NIL_NODE;
size_t index = 0;
while (next_edge(&e.tail, &e.head, &e.weight)) {
if (config->lc_direction == LL_L_UNDIRECTED_ORDERED) {
if (e.tail > e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
}
}
if (config->lc_deduplicate && last_head == e.head
&& last_tail == e.tail) {
continue;
}
#ifdef LL_MLCSR_CONTINUATIONS
if (last_tail != e.tail) {
auto& vt_value = (*vt)[e.tail];
assert(LL_EDGE_LEVEL(vt_value.adj_list_start)
== new_level);
index = LL_EDGE_INDEX(vt_value.adj_list_start);
}
#endif
last_head = e.head;
last_tail = e.tail;
(*et)[index] = LL_VALUE_CREATE((node_t) e.head);
if (HasWeight && load_weight) {
edge_t edge = LL_EDGE_CREATE(new_level, index);
prop_weight->cow_write(edge, e.weight);
}
if (reverse) {
xs_in_edge x;
x.head = e.head;
x.tail = e.tail;
#ifdef LL_LOAD_CREATE_REV_EDGE_MAP
x.out_edge = edge;
#endif
*in_sort << x;
}
index++;
if (print_progress) {
if (index % step == 0) {
fprintf(stderr, ".");
if (index % (step * 10) == 0) {
fprintf(stderr, "%lu", index / 1000000ul);
}
}
}
}
#ifndef LL_MLCSR_CONTINUATIONS
assert(index == max_edges);
#endif
}
else /* if (!already_sorted) */ {
if (out_called_sort)
out_sort->rewind_sorted();
else
out_sort->sort();
xs_w_edge* buffer;
size_t length;
size_t index = 0;
last_tail = LL_NIL_NODE;
last_head = LL_NIL_NODE;
while (out_sort->next_block(&buffer, &length)) {
while (length --> 0) {
if (config->lc_deduplicate && last_head == buffer->head
&& last_tail == buffer->tail) {
buffer++;
continue;
}
#ifdef LL_MLCSR_CONTINUATIONS
if (last_tail != buffer->tail) {
auto& vt_value = (*vt)[buffer->tail];
assert(LL_EDGE_LEVEL(vt_value.adj_list_start)
== new_level);
index = LL_EDGE_INDEX(vt_value.adj_list_start);
}
#endif
last_head = buffer->head;
last_tail = buffer->tail;
(*et)[index] = LL_VALUE_CREATE((node_t) buffer->head);
if (HasWeight && load_weight) {
edge_t edge = LL_EDGE_CREATE(new_level, index);
prop_weight->cow_write(edge, e.weight);
}
if (reverse) {
xs_in_edge x;
x.head = buffer->head;
x.tail = buffer->tail;
#ifdef LL_LOAD_CREATE_REV_EDGE_MAP
x.out_edge = edge;
#endif
*in_sort << x;
}
index++;
buffer++;
if (print_progress) {
if (index % step == 0) {
fprintf(stderr, ".");
if (index % (step * 10) == 0) {
fprintf(stderr, "%lu", index / 1000000ul);
}
}
}
}
}
delete out_sort;
out_sort = NULL;
} /* Ends: if (already_sorted) { ... } else { ... } */
graph->out().finish_level_edges();
if (HasWeight && load_weight) {
prop_weight->finish_level();
}
/*
* PASS 3
* - Compute the in-edges, if applicable
*/
// Do the in-edges
if (reverse) {
if (print_progress) {
fprintf(stderr, "[I]");
}
graph->in().init_level_from_degrees(max_nodes, degrees_in, NULL);
et = graph->in().edge_table(new_level);
vt = graph->in().vertex_table(new_level); (void) vt;
// If the out-to-in, in-to-out properties are not enabled, disable
// that feature in the corresponding ll_csr_base
if (!config->lc_reverse_edges || !config->lc_reverse_maps) {
graph->in().set_edge_translation(false);
}
// Sort the in edges and load them
in_sort->sort();
xs_in_edge* buffer;
size_t length;
size_t index = 0;
last_head = LL_NIL_NODE;
last_tail = LL_NIL_NODE;
while (in_sort->next_block(&buffer, &length)) {
while (length --> 0) {
#ifdef LL_MLCSR_CONTINUATIONS
if (last_head != buffer->head) {
auto& vt_value = (*vt)[buffer->head];
assert(LL_EDGE_LEVEL(vt_value.adj_list_start)
== new_level);
index = LL_EDGE_INDEX(vt_value.adj_list_start);
}
#endif
last_head = buffer->head;
last_tail = buffer->tail;
(*et)[index] = LL_VALUE_CREATE((node_t) buffer->tail);
// TODO Do the out-to-in, in-to-out properties if desired
index++;
buffer++;
if (print_progress) {
if (index % step == 0) {
fprintf(stderr, ".");
if (index % (step * 10) == 0) {
fprintf(stderr, "%lu", index / 1000000ul);
}
}
}
}
}
delete in_sort;
in_sort = NULL;
graph->in().finish_level_edges();
}
// Finish
if (reverse) free(degrees_in);
free(degrees_out);
_last_has_more = _has_more;
_has_more = false;
return true;
}
/**
* Load the data into one or more queues of requests
*
* @param request_queues the request queues
* @param num_stripes the number of stripes (queues array length)
* @param config the loader configuration
* @return true if there are more edges to load
*/
bool load_to_request_queues(ll_la_request_queue** request_queues,
size_t num_stripes, const ll_loader_config* config) {
// Check features
feature_vector_t features;
features << LL_L_FEATURE(lc_max_edges);
features << LL_L_FEATURE(lc_no_properties);
config->assert_features(false /*direct*/, true /*error*/, features);
// Initializie
size_t max_edges = 0;
size_t chunk_size = config->lc_max_edges;
bool load_weight = !config->lc_no_properties;
xs_w_edge e;
bool has_more;
while ((has_more = next_edge(&e.tail, &e.head, &e.weight))) {
max_edges++;
LL_D_NODE2_PRINT(e.tail, e.head, "%u --> %u\n", (unsigned) e.tail,
(unsigned) e.head);
ll_la_request_with_edge_properties* request;
if (HasWeight && load_weight) {
// XXX
//LL_NOT_IMPLEMENTED;
}
#ifdef LL_S_WEIGHTS_INSTEAD_OF_DUPLICATE_EDGES
request = new ll_la_add_edge_for_streaming_with_weights
<node_t>((node_t) e.tail, (node_t) e.head);
#else
request = new ll_la_add_edge
<node_t>((node_t) e.tail, (node_t) e.head);
#endif
size_t stripe = (e.tail >> (LL_ENTRIES_PER_PAGE_BITS+3))
% num_stripes;
request_queues[stripe]->enqueue(request);
if (chunk_size > 0)
if (max_edges % chunk_size == 0) break;
}
return has_more;
}
/**
* Load the graph into the writable representation
*
* @param graph the graph
* @param config the loader configuration
* @return true on no error
*/
bool load_incremental(ll_writable_graph* graph,
const ll_loader_config* config) {
// Check features
feature_vector_t features;
features << LL_L_FEATURE(lc_max_edges);
features << LL_L_FEATURE(lc_no_properties);
config->assert_features(false /*direct*/, true /*error*/, features);
// Initializie
size_t num_stripes = omp_get_max_threads();
ll_la_request_queue* request_queues[num_stripes];
for (size_t i = 0; i < num_stripes; i++) {
request_queues[i] = new ll_la_request_queue();
}
LL_D_PRINT("Initialize\n");
// TODO Deduplicate? Unordered?
// TODO Create nodes
bool has_more = true;
while (has_more) {
graph->tx_begin();
for (size_t i = 0; i < num_stripes; i++)
request_queues[i]->shutdown_when_empty(false);
#pragma omp parallel
{
if (omp_get_thread_num() == 0) {
has_more = this->load_to_request_queues(request_queues,
num_stripes, config);
// Add a worker
for (size_t i = 0; i < num_stripes; i++)
request_queues[i]->shutdown_when_empty();
for (size_t i = 0; i < num_stripes; i++)
request_queues[i]->run(*graph);
}
else {
int t = omp_get_thread_num();
for (size_t i = 0; i < num_stripes; i++, t++)
request_queues[t % num_stripes]->worker(*graph);
}
}
graph->tx_commit();
if (has_more) break;
}
_last_has_more = _has_more;
_has_more = has_more;
for (size_t i = 0; i < num_stripes; i++) delete request_queues[i];
return true;
}
/**
* Load the next batch of data
*
* @param graph the writable graph
* @param max_edges the maximum number of edges
* @return true if data was loaded, false if there are no more data
*/
virtual bool pull(ll_writable_graph* graph, size_t max_edges) {
ll_loader_config config;
config.lc_max_edges = max_edges;
if (!load_incremental(graph, &config)) abort();
return _last_has_more;
}
/**
* Load the next batch of data to request queues
*
* @param request_queues the request queues
* @param num_stripes the number of stripes (queues array length)
* @param max_edges the maximum number of edges
* @return true if data was loaded, false if there are no more data
*/
virtual bool pull(ll_la_request_queue** request_queues, size_t num_stripes,
size_t max_edges) {
ll_loader_config config;
config.lc_max_edges = max_edges;
bool has_more = load_to_request_queues(request_queues, num_stripes,
&config);
_last_has_more = _has_more;
_has_more = has_more;
return _last_has_more;
}
private:
/**
* Initialize the weights property (if applicable)
*
* @param graph the graph
* @param config the loader configuration
* @return the property, or NULL if not applicable
*/
ll_mlcsr_edge_property<WeightType>* init_prop_weight(
ll_mlcsr_ro_graph* graph) {
if (!HasWeight) return NULL;
size_t new_level = graph->out().num_levels() - 1;
size_t et_length = graph->out().edge_table_length(new_level);
ll_mlcsr_edge_property<WeightType>* prop_weight = NULL;
if (sizeof(WeightType) == 4) {
prop_weight
= reinterpret_cast<ll_mlcsr_edge_property<WeightType>*>
(graph->get_edge_property_32("weight"));
if (prop_weight == NULL) {
prop_weight
= reinterpret_cast<ll_mlcsr_edge_property<WeightType>*>
(graph->create_uninitialized_edge_property_32
("weight", WeightTypeCode));
prop_weight->ensure_min_levels(new_level, et_length);
}
}
else {
if (sizeof(WeightType) != 8) abort();
prop_weight
= reinterpret_cast<ll_mlcsr_edge_property<WeightType>*>
(graph->get_edge_property_64("weight"));
if (prop_weight == NULL) {
prop_weight
= reinterpret_cast<ll_mlcsr_edge_property<WeightType>*>
(graph->create_uninitialized_edge_property_64
("weight", WeightTypeCode));
prop_weight->ensure_min_levels(new_level, et_length);
}
}
prop_weight->cow_init_level(et_length);
return prop_weight;
}
/**
* Write a node with its out-edges and prep for the in-edges
*
* @param graph the graph
* @param et the edge table
* @param new_level the new level
* @param node the node
* @param adj_list the adjacency list
* @param weights the weights (if applicable)
* @param prop_weight the weights property (if applicable)
* @param in_sort the in-edges sorter (if applicable)
*/
void load_node_out(ll_mlcsr_ro_graph* graph, LL_ET<node_t>* et, size_t new_level,
node_t node, std::vector<NodeType>& adj_list,
std::vector<WeightType>& weights,
ll_mlcsr_edge_property<WeightType>* prop_weight,
ll_external_sort<xs_in_edge, xs_in_edge_comparator>* in_sort) {
size_t et_index = graph->out().init_node(node, adj_list.size(), 0);
edge_t edge = LL_EDGE_CREATE(new_level, et_index);
for (size_t i = 0; i < adj_list.size(); i++) {
LL_D_NODE2_PRINT(node, adj_list[i], "%ld --> %ld\n",
(long) node, (long) adj_list[i]);
(*et)[et_index + i] = LL_VALUE_CREATE((node_t) adj_list[i]);
}
if (in_sort != NULL) {
xs_in_edge x;
x.tail = node;
for (size_t i = 0; i < adj_list.size(); i++) {
x.head = adj_list[i];
#ifdef LL_LOAD_CREATE_REV_EDGE_MAP
x.out_edge = edge + i;
#endif
*in_sort << x;
}
}
if (HasWeight) {
for (size_t i = 0; i < weights.size(); i++) {
prop_weight->cow_write(edge + i, weights[i]);
}
}
}
/**
* Write a node with its in-edges
*
* @param graph the graph
* @param et the edge table
* @param new_level the new level
* @param node the node
* @param adj_list the adjacency list
*/
void load_node_in(ll_mlcsr_ro_graph* graph, LL_ET<node_t>* et, size_t new_level,
node_t node, std::vector<NodeType>& adj_list) {
size_t et_index = graph->in().init_node(node, adj_list.size(), 0);
for (size_t i = 0; i < adj_list.size(); i++) {
(*et)[et_index + i] = LL_VALUE_CREATE((node_t) adj_list[i]);
}
}
/**
* Load the graph directly into the read-only representation for the case
* in which the ll_edge_list_loader::stat() info is readily available
*
* @param graph the graph
* @param config the loader configuration
* @return true on no error
*/
bool load_direct_with_stat(ll_mlcsr_ro_graph* graph,
const ll_loader_config* config) {
// Check features
feature_vector_t features;
features << LL_L_FEATURE(lc_direction);
features << LL_L_FEATURE(lc_reverse_edges);
features << LL_L_FEATURE(lc_deduplicate);
features << LL_L_FEATURE(lc_no_properties);
features << LL_L_FEATURE(lc_max_edges);
config->assert_features(false /*direct*/, true /*error*/, features);
// Initialize the algorithm
bool print_progress = config->lc_print_progress;
bool reverse = config->lc_reverse_edges;
bool load_weight = !config->lc_no_properties;
size_t new_level = graph->num_levels();
size_t max_nodes = 0;
size_t max_edges = 0;
xs_w_edge e;
if (!stat(&max_nodes, &max_edges)) {
LL_E_PRINT("The graph stat call failed\n");
abort();
}
if (config->lc_max_edges > 0 && max_edges > config->lc_max_edges) {
max_edges = config->lc_max_edges;
}
if (new_level > 0) {
if (max_nodes < (size_t) graph->out().max_nodes()) {
max_nodes = graph->out().max_nodes();
}
}
if (config->lc_direction == LL_L_UNDIRECTED_DOUBLE) {
max_edges *= 2;
}
// Initialize the new CSR level
graph->partial_init_level(max_nodes, max_nodes, max_edges);
LL_ET<node_t>* et = graph->out().edge_table(new_level);
LL_D_PRINT("Nodes = %lu, edges = %lu\n", max_nodes, max_edges);
ll_mlcsr_edge_property<WeightType>* prop_weight = NULL;
if (load_weight) prop_weight = init_prop_weight(graph);
// If the out-to-in, in-to-out properties are not enabled, disable
// that feature in the corresponding ll_csr_base
if (!config->lc_reverse_edges || !config->lc_reverse_maps) {
graph->out().set_edge_translation(false);
graph->in().set_edge_translation(false);
}
// Initialize the in-edges
ll_external_sort<xs_in_edge, xs_in_edge_comparator>* in_sort = NULL;
if (reverse) {
graph->partial_init_level_in(max_nodes, max_nodes, max_edges);
in_sort = new ll_external_sort<xs_in_edge,
xs_in_edge_comparator>(config);
}
/*
*
* CASE 1: The input file is sorted
*
*/
// Try to load the data if it is sorted -- or discover that it is not,
// abort, and then try again with the external sort
size_t loaded_edges = 0;
bool was_sorted = false;
size_t step = 10 * 1000 * 1000ul;
if (print_progress) {
fprintf(stderr, "[<]");
}
if (config->lc_direction != LL_L_UNDIRECTED_DOUBLE) {
std::vector<NodeType> adj_list_buffer;
std::vector<WeightType> weight_buffer;
NodeType last_tail = (NodeType) LL_NIL_NODE;
NodeType last_head = (NodeType) LL_NIL_NODE;
was_sorted = true;
while (next_edge(&e.tail, &e.head, &e.weight)) {
loaded_edges++;
if (config->lc_max_edges > 0
&& loaded_edges > config->lc_max_edges) {
break;
}
LL_D_NODE2_PRINT(e.tail, e.head, "%ld --> %ld\n", (long) e.tail,
(long) e.head);
if (config->lc_direction == LL_L_UNDIRECTED_ORDERED) {
if (e.tail > e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
}
}
if (config->lc_deduplicate && last_head == e.head
&& last_tail == e.tail) {
continue;
}
if ((last_tail != (NodeType) LL_NIL_NODE && last_tail > e.tail)
|| (last_tail == e.tail && last_head > e.head)) {
LL_D_PRINT("The input file is not sorted\n");
was_sorted = false;
loaded_edges = 0;
rewind();
graph->out().restart_init_level();
if (in_sort != NULL) in_sort->clear();
break;
}
// Init the node and write the edges after we moved to the next
// node
if (last_tail != e.tail && last_tail != (NodeType) LL_NIL_NODE) {
load_node_out(graph, et, new_level, last_tail, adj_list_buffer,
weight_buffer, prop_weight, in_sort);
adj_list_buffer.clear();
weight_buffer.clear();
}
last_head = e.head;
last_tail = e.tail;
// Load the edge into the buffer
adj_list_buffer.push_back(e.head);
if (HasWeight && load_weight) weight_buffer.push_back(e.weight);
// Progress
if (print_progress) {
if (loaded_edges % step == 0) {
fprintf(stderr, ".");
if (loaded_edges % (step * 10) == 0) {
fprintf(stderr, "%lu", loaded_edges / 1000000ul);
}
}
}
}
// Finish the buffer
if (was_sorted && last_tail != (NodeType) LL_NIL_NODE) {
load_node_out(graph, et, new_level, last_tail, adj_list_buffer,
weight_buffer, prop_weight, in_sort);
}
}
/*
*
* CASE 2: The input file is not sorted
*
*/
// Now if the buffer was not sorted, load it using the external sort
if (!was_sorted) {
ll_external_sort<xs_w_edge, xs_w_edge_comparator>* out_sort
= new ll_external_sort<xs_w_edge, xs_w_edge_comparator>(config);
NodeType last_tail = (NodeType) LL_NIL_NODE;
NodeType last_head = (NodeType) LL_NIL_NODE;
size_t read_edges = 0;
while (next_edge(&e.tail, &e.head, &e.weight)) {
loaded_edges++;
read_edges++;
if (config->lc_max_edges > 0
&& read_edges > config->lc_max_edges) {
break;
}
if (config->lc_direction == LL_L_UNDIRECTED_ORDERED) {
if (e.tail > e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
}
}
if (config->lc_deduplicate && last_head == e.head
&& last_tail == e.tail) {
continue;
}
last_head = e.head;
last_tail = e.tail;
*out_sort << e;
if (config->lc_direction == LL_L_UNDIRECTED_DOUBLE) {
if (e.tail != e.head) {
unsigned x = e.tail; e.tail = e.head; e.head = x;
*out_sort << e;
loaded_edges++;
}
}
// Progress
if (print_progress) {
if (loaded_edges % step == 0) {
fprintf(stderr, ".");
if (loaded_edges % (step * 10) == 0) {
fprintf(stderr, "%lu", loaded_edges / 1000000ul);
}
}
}
}
out_sort->sort();
xs_w_edge* buffer;
size_t length;
std::vector<NodeType> adj_list_buffer;
std::vector<WeightType> weight_buffer;
last_tail = (NodeType) LL_NIL_NODE;
last_head = (NodeType) LL_NIL_NODE;
if (print_progress) {
fprintf(stderr, "[+]");
}
while (out_sort->next_block(&buffer, &length)) {
while (length --> 0) {
if (config->lc_deduplicate && last_head == buffer->head
&& last_tail == buffer->tail) {
buffer++;
continue;
}
// Init the node and write the edges after we moved to the
// next node
if (last_tail != buffer->tail
&& last_tail != (NodeType) LL_NIL_NODE) {
load_node_out(graph, et, new_level, last_tail,
adj_list_buffer, weight_buffer, prop_weight,
in_sort);
adj_list_buffer.clear();
weight_buffer.clear();
}
last_head = buffer->head;
last_tail = buffer->tail;
// Load the edge into the buffer
adj_list_buffer.push_back(buffer->head);
if (HasWeight && load_weight)
weight_buffer.push_back(e.weight);
buffer++;
// Progress
if (print_progress) {
if (loaded_edges % step == 0) {
fprintf(stderr, ".");
if (loaded_edges % (step * 10) == 0) {
fprintf(stderr, "%lu", loaded_edges / 1000000ul);
}
}
}
}
}
// Finish the buffer
if (last_tail != (NodeType) LL_NIL_NODE) {
load_node_out(graph, et, new_level, last_tail, adj_list_buffer,
weight_buffer, prop_weight, in_sort);
}
}
/*
*
* Finish up the out-edges and do the in-edges
*
*/
graph->out().finish_level_vertices();
graph->out().finish_level_edges();
if (HasWeight && load_weight) {
prop_weight->finish_level();
}
if (reverse) {
if (print_progress) {
fprintf(stderr, "[I]");
}
// If the out-to-in, in-to-out properties are not enabled, disable
// that feature in the corresponding ll_csr_base
if (!config->lc_reverse_edges || !config->lc_reverse_maps) {
graph->in().set_edge_translation(false);
}
// Sort the in-edges and load them
in_sort->sort();
xs_in_edge* buffer;
size_t length;
loaded_edges = 0;
et = graph->in().edge_table(new_level);
NodeType last_head = (NodeType) LL_NIL_NODE;
std::vector<NodeType> adj_list_buffer;
std::vector<WeightType> weight_buffer;
while (in_sort->next_block(&buffer, &length)) {
while (length --> 0) {
// Init the node and write the edges after we moved to the
// next node
if (last_head != buffer->head && last_head != (NodeType) LL_NIL_NODE) {
load_node_in(graph, et, new_level, last_head, adj_list_buffer);
adj_list_buffer.clear();
}
last_head = buffer->head;
// Load the edge into the buffer
adj_list_buffer.push_back(buffer->tail);
buffer++;
// Progress
if (print_progress) {
if (loaded_edges % step == 0) {
fprintf(stderr, ".");
if (loaded_edges % (step * 10) == 0) {
fprintf(stderr, "%lu", loaded_edges / 1000000ul);
}
}
}
}
}
// Finish the buffer
if (last_head != (NodeType) LL_NIL_NODE) {
load_node_in(graph, et, new_level, last_head, adj_list_buffer);
}
// Finish the in-edges
delete in_sort;
in_sort = NULL;
graph->in().finish_level_vertices();
graph->in().finish_level_edges();
}
// Finish
_last_has_more = _has_more;
_has_more = false;
return true;
}
};
#endif
|
b53415bfb16422a4fdd1c3a270d783d0467cdb11
|
796f8851d2509455dc2f89592a51bcd8d022948d
|
/20190119-3주차-3일차/전현승/B.cpp
|
60235329b5a39a17b8823cc6b04296d09268428f
|
[] |
no_license
|
rhythm-union/2019-algorithm-study
|
ade8c4adedea0acf54f1183a1e6a3c8eaed814f0
|
92e6ad25b0cf9614f5f7da734a547d12302c0491
|
refs/heads/master
| 2020-04-14T02:24:44.056689
| 2019-02-15T17:56:45
| 2019-02-15T17:56:45
| 163,582,114
| 9
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 667
|
cpp
|
B.cpp
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef DEBUG
freopen("in.txt", "r", stdin);
#endif
int w[3404], d[3404], dp[2][12882] = {0, };
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> d[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
dp[i % 2][j] = dp[1 - i % 2][j];
}
for (int j = w[i]; j <= m; j++) {
dp[i % 2][j] = max(dp[i % 2][j], dp[1 - i % 2][j - w[i]] + d[i]);
}
}
cout << dp[n % 2][m] << '\n';
return 0;
}
|
da0aa4418ec810c29cba79156378245cfe3188d1
|
81ff4f4476fb8ad5b9df7a584bf21bfc38a5750a
|
/Arduino/tresLedSend/tresLedSend.ino
|
11c441cf18928bde4e9596c7ca78f5883f82ea32
|
[] |
no_license
|
numantino/cursosUdemy
|
59e1906ab9f915279819984685e1fcc10618abd9
|
7d8d218820002c1e5601554a4720cdf9125b331e
|
refs/heads/main
| 2023-08-27T08:07:31.467961
| 2021-10-28T17:06:31
| 2021-10-28T17:06:31
| 314,204,353
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,369
|
ino
|
tresLedSend.ino
|
#include <EEPROM.h>
#define LED_PIN_R 12
#define LED_PIN_A 11
#define LED_PIN_V 10
#define LED_PIN_B 9
#define MAX_ARRAY 4
#define VAL_LED_INICIAL 0
int arrayLed[MAX_ARRAY] = {LED_PIN_R,LED_PIN_A,LED_PIN_V,LED_PIN_B};
void apagarTodosLed(){
//Apagamos todos los leds
for (int i=0;i<MAX_ARRAY;i++) digitalWrite(arrayLed[i],LOW);
}
void encenderLed(int pos_led){
//Encendemos el led indicado
if (pos_led>=0 && pos_led<MAX_ARRAY){
digitalWrite(arrayLed[pos_led],HIGH);
}
}
void inicializacion(){
Serial.println("Inicializacion");
//Inicializamos puertos
for (int i=0;i<MAX_ARRAY;i++) pinMode(arrayLed[i],OUTPUT);
//Apagamos la luces
apagarTodosLed();
//Recuperamos informacion de memoria
int va_inicial_led=EEPROM.read(VAL_LED_INICIAL);
encenderLed(va_inicial_led);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Ejercicio comunicacion");
//Inicializacion
inicializacion();
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0){
int pos_led=Serial.parseInt();
//apagamos todos primero
//encendemos el que nos indican
if (pos_led>0 && pos_led<=MAX_ARRAY){
apagarTodosLed();
encenderLed(pos_led-1);
//Almacenamos el valor en memoria
EEPROM.write(VAL_LED_INICIAL,pos_led-1);
}
}
}
|
cd1e8fad65d76cdd0357488820b2203d5f355380
|
a1684f4bde0322f2acab6c33ce137fbf9585faf6
|
/Src/ShadowFX/CSHFXResourceMgr.cpp
|
105eedf52b0d4959408f79750b45336b3179d895
|
[] |
no_license
|
benyeoh/arf
|
339fd592c0fb000ad8827f8aa1b1fa4c612d9d87
|
42514908f5478c476bb00802035fa2a3253811f5
|
refs/heads/master
| 2021-12-31T10:36:27.501754
| 2021-12-19T15:13:56
| 2021-12-19T15:13:56
| 181,698,538
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,109
|
cpp
|
CSHFXResourceMgr.cpp
|
//==============================================================================
//
// CSHFXResourceMgr.cpp
//
// A description here
//
// Author: Ben Yeoh
// Date: 8/15/2008
//
//==============================================================================
#include "ShadowFXFramework.h"
_NAMESPACE_BEGIN
ISHFXCascadedDirLight*
CSHFXResourceMgr::CreateCascadedDirLight()
{
CSHFXCascadedDirLight* pToReturn = _NEW CSHFXCascadedDirLight(m_pShadowFX);//, 1024, 4);
_DEBUG_ASSERT(((uint) (size_t) pToReturn->GetProj().cascadedViewProj) % 16 == 0);
return pToReturn;
}
ISHFXPointLight*
CSHFXResourceMgr::CreatePointLight()
{
CSHFXPointLight* pToReturn = _NEW CSHFXPointLight(m_pShadowFX);//, 256, 5);
return pToReturn;
}
ISHFXCubePointLight* CSHFXResourceMgr::CreateCubePointLight()
{
CSHFXCubePointLight* pToReturn = _NEW CSHFXCubePointLight(m_pShadowFX);
return pToReturn;
}
eRTexFormat CSHFXResourceMgr::GetSMCompatibleFormat()
{
// NOTE: G16R16 is slow on some GPUs (like ATI 5800)
return TEXF_G16R16;
}
eRDepthFormat CSHFXResourceMgr::GetSMCompatibleDepthFormat()
{
return DF_D24S8;
}
//IRTextureRT* CSHFXResourceMgr::CreateCascadedDirLightExpShadowMap(uint size)
//{
// return m_pShadowFX->GetRenderer().GetRResourceMgr().CreateTextureRT(size, size, TEXF_R32F);
//}
//
//IRTextureRT* CSHFXResourceMgr::CreatePointLightExpShadowMap(uint size)
//{
// return m_pShadowFX->GetRenderer().GetRResourceMgr().CreateTextureRT(size, size, TEXF_G32R32F);
//}
//
//IRDepthBuffer* CSHFXResourceMgr::CreateShadowMapDepthBuffer(uint size)
//{
// return m_pShadowFX->GetRenderer().GetRResourceMgr().CreateDepthBuffer(size, size, DF_D24S8, 0);
//}
ISHFXPipeline* CSHFXResourceMgr::CreatePipeline()
{
CSHFXPipeline* pPipeline = _NEW CSHFXPipeline();
pPipeline->SetShadowFX(m_pShadowFX);
pPipeline->Initialize();
return pPipeline;
}
ISHFXParamPool* CSHFXResourceMgr::CreateParamPool()
{
CSHFXParamPool* pPool = _NEW CSHFXParamPool();
pPool->SetShadowFX(m_pShadowFX);
return pPool;
}
_NAMESPACE_END
|
a5c10b36754f1b25375e3af7c1f5d78c2b43288a
|
d0e4275244e0eba2b0c1fc2c518e04f0212e3bac
|
/uva/triangle.cpp
|
ece33a011a63e16560ae22465e208b3fc6ebc40f
|
[] |
no_license
|
IamYourAlpha/CONTEST-CODES
|
0b34ba29ef7cfa725539c069bc8a1e3ba5b8e54f
|
e8b12e08af53fcff4bdc08cc7a42eecd5598a83d
|
refs/heads/master
| 2021-06-08T13:00:35.511893
| 2021-02-26T07:44:45
| 2021-02-26T07:44:45
| 97,600,150
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 569
|
cpp
|
triangle.cpp
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll gcd(ll a,ll b) {
ll t;
while(b) {
a=a%b;
t=a;
a=b;
b=t;
}
return a;
}
int bamboo[100];
int main(){
//freopen("input.txt","r",stdin);
int tc;
cin >> tc;
int n;
while(tc--){
scanf("%d",&n);
bamboo[1]=1;
bamboo[2]=1;
for(int i=3;i<=15;i++) bamboo[i]=(i-1);
int tot = 0;
for(int i=1;i<=n;i++) tot = tot + bamboo[i];
// cout << tot << endl;
cout << tot-(n-1) << endl;
}
return 0;
}
|
d5143e4dbefb6f16c37b985008c9e839216b8f5d
|
a21d7710b1d193ae7ee12205c2af2c47db09905e
|
/LeetCode/Problems/Algorithms/#782_TransformToChessboard_sol4_greedy_and_bit_manipulation_O(N^2)_time_O(1)_extra_space_8ms_10.3MB.cpp
|
e11c69691ae766bd19e97476ffad88d84181c316
|
[
"MIT"
] |
permissive
|
Tudor67/Competitive-Programming
|
0db89e0f8376cac7c058185b84fdf11dcb99dae8
|
827cabc45951ac33f63d1d6e69e57897207ea666
|
refs/heads/master
| 2023-08-19T05:22:10.451067
| 2023-08-14T21:21:51
| 2023-08-14T21:21:51
| 243,604,510
| 5
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,736
|
cpp
|
#782_TransformToChessboard_sol4_greedy_and_bit_manipulation_O(N^2)_time_O(1)_extra_space_8ms_10.3MB.cpp
|
class Solution {
private:
const int INF = 1e9;
bool isChessBoard(const vector<vector<int>>& BOARD){
const int N = BOARD.size();
for(int row = 0; row < N; ++row){
for(int col = 0; col < N; ++col){
if(row >= 1 && BOARD[row - 1][col] == BOARD[row][col]){
return false;
}
if(col >= 1 && BOARD[row][col - 1] == BOARD[row][col]){
return false;
}
}
}
return true;
}
set<int> getMaskSet3(const vector<vector<int>>& BOARD, bool isTransposed = false){
const int N = BOARD.size();
set<int> maskSet;
for(int i = 0; i < N; ++i){
int mask = 0;
for(int j = 0; j < N; ++j){
if(isTransposed){
mask = 2 * mask + BOARD[j][i];
}else{
mask = 2 * mask + BOARD[i][j];
}
}
maskSet.insert(mask);
if((int)maskSet.size() >= 3){
break;
}
}
return maskSet;
}
int getMinMoves(set<int>& maskSet, int mask0, int mask1, int boardZeros, int boardOnes, const int& N){
int minMoves = INF;
for(int mask: maskSet){
int maskOnes = __builtin_popcount((unsigned int)mask);
int maskZeros = N - maskOnes;
int moves = INF;
int movesToMask0 = __builtin_popcount((unsigned int)(mask ^ mask0)) / 2;
int movesToMask1 = __builtin_popcount((unsigned int)(mask ^ mask1)) / 2;
if(boardZeros < boardOnes){
if(maskZeros < maskOnes){
moves = movesToMask1;
}
}else if(boardZeros > boardOnes){
if(maskZeros > maskOnes){
moves = movesToMask0;
}
}else{
moves = min(movesToMask0, movesToMask1);
}
minMoves = min(minMoves, moves);
}
return minMoves;
}
public:
int movesToChessboard(vector<vector<int>>& board) {
const int N = board.size();
// Step 1: check if board is a chessboard
if(isChessBoard(board)){
return 0;
}
// Step 2: sanity check
set<int> rowMasks = getMaskSet3(board, false);
set<int> colMasks = getMaskSet3(board, true);
if((int)rowMasks.size() != 2 || (int)colMasks.size() != 2){
return -1;
}
int firstRowOnes = __builtin_popcount((unsigned int)*rowMasks.begin());
int firstRowZeros = N - firstRowOnes;
int secondRowOnes = __builtin_popcount((unsigned int)*rowMasks.rbegin());
int secondRowZeros = N - secondRowOnes;
int firstColOnes = __builtin_popcount((unsigned int)*colMasks.begin());
int firstColZeros = N - firstColOnes;
int secondColOnes = __builtin_popcount((unsigned int)*colMasks.rbegin());
int secondColZeros = N - secondColOnes;
if(abs(firstRowOnes - firstRowZeros) > N % 2 || abs(secondRowOnes - secondRowZeros) > N % 2 ||
abs(firstColOnes - firstColZeros) > N % 2 || abs(secondColOnes - secondColZeros) > N % 2){
return -1;
}
// Step 3: compute min moves using a greedy approach:
// - fix the value of the starting row and starting column
// (depending on the total number of zeros and ones in the board);
// - fix the index of the starting row and starting column
// (depending on the total number of zeros and ones in the board);
// - find bad rows and bad cols;
// - count the number of swaps for bad rows (= badRows / 2);
// - count the number of swaps for bad cols (= badCols / 2);
// - update the answer;
int boardZeros = 0;
int boardOnes = 0;
for(int row = 0; row < N; ++row){
for(int col = 0; col < N; ++col){
boardZeros += (board[row][col] == 0);
boardOnes += (board[row][col] == 1);
}
}
int mask0 = 0;
int mask1 = 0;
for(int bit = 0; bit < N; ++bit){
mask0 |= (bit % 2) << bit;
mask1 |= ((bit + 1) % 2) << bit;
}
return getMinMoves(rowMasks, mask0, mask1, boardZeros, boardOnes, N) +
getMinMoves(colMasks, mask0, mask1, boardZeros, boardOnes, N);
}
};
|
9b185c38388883be82d4ff79b866aaf03c78a0ed
|
72c0fb28326ee8c4a453d22b607febfaa579dd78
|
/ClsMonitor/Process/KillProcessScheduler.cpp
|
1f0debc79bd66ea9b4180bb73a3638a20b454b3f
|
[
"MIT"
] |
permissive
|
inker610566/ClsMonitor
|
cf53242bd0f577db6967c3498149a20ab0286d53
|
185dd3ac4bdde0e8dcaa1dfeacf263d136fe0cdd
|
refs/heads/master
| 2020-07-09T21:53:06.957846
| 2016-12-05T19:20:41
| 2016-12-05T19:20:41
| 74,028,408
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,394
|
cpp
|
KillProcessScheduler.cpp
|
#include "KillProcessScheduler.h"
#include "../Utils/ConsoleLogger.h"
namespace Process
{
const wchar_t *ScreenLockerPath = L"C:\\Program Files (x86)\\ClsMonitor\\ScreenLocker.exe";
Process::KillProcessScheduler::KillProcessScheduler(Blacklist *init_list, WMIServiceProxy * service)
:list(init_list), service(service), init_set(init_list->CopyBlist()), IsScreenLockerStart(false)
{
}
void Process::KillProcessScheduler::Add(std::wstring name)
{
queue.Push(new QueueEvent(Process::Add, name));
}
void Process::KillProcessScheduler::Del(std::wstring name)
{
queue.Push(new QueueEvent(Process::Del, name));
}
void KillProcessScheduler::Kill(std::wstring name)
{
queue.Push(new QueueEvent(Process::Kill, name));
}
void KillProcessScheduler::LockScreen()
{
queue.Push(new QueueEvent(Process::LockScreen));
}
void Process::KillProcessScheduler::Reset()
{
queue.Push(new QueueEvent(Process::Reset));
}
void Process::KillProcessScheduler::ExecuteLoop()
{
while (true)
{
QueueEvent* evt = queue.Pop();
switch (evt->type)
{
case Process::Add:
list->Add(evt->Name);
service->TerminateProcessesWithName(evt->Name);
break;
case Process::Del:
list->Del(evt->Name);
break;
case Process::Kill:
service->TerminateProcessesWithName(evt->Name);
break;
case Process::Reset:
list->SetToBlist(init_set);
for (auto s: init_set)
service->TerminateProcessesWithName(s);
break;
case Process::LockScreen:
if (!IsScreenLockerStart)
{
DoLockScreen();
}
break;
}
delete evt;
}
}
DWORD WINAPI Wait4Thread(
_In_ LPVOID lpParameter
)
{
KillProcessScheduler *kpsch = (KillProcessScheduler*)lpParameter;
STARTUPINFO info={sizeof(info)};
PROCESS_INFORMATION processInfo;
if (CreateProcessW(
ScreenLockerPath,
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&info,
&processInfo))
{
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
else
{
ConsoleLogger::getInstance()->log("Cannot start ScreenLocker");
}
kpsch->IsScreenLockerStart = false;
return 0;
}
void KillProcessScheduler::DoLockScreen()
{
IsScreenLockerStart = true;
DWORD threadid;
HANDLE thread = CreateThread(
NULL,
0,
Wait4Thread,
this,
0,
&threadid
);
}
}
|
80e93f65bbc4b636631c74776ebfed733aebd987
|
8a0e9e926f488873d8e1ee98f2eb90649c234a8b
|
/include/cavi/core.h
|
ab241c044a9a61e2857744c60deaf888efb92ac0
|
[
"BSL-1.0"
] |
permissive
|
bnbajwa/cavi
|
667b99b034686912c9c8437a63575630e4c8d04f
|
2963230ebce3500993644bd3186035c45d51af88
|
refs/heads/main
| 2023-07-15T19:48:40.438410
| 2021-08-26T12:03:00
| 2021-08-26T12:03:00
| 400,142,673
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 28,880
|
h
|
core.h
|
// Copyright Baber Nawaz 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
#ifndef CAVI_HEADER_CAVI_H
#define CAVI_HEADER_CAVI_H
#include "lib.h"
#include "mp.h"
namespace cavi {
template<typename T, typename BaseTsL>
struct class_def;
template<typename... ClassDefTs>
struct hierarchy_def;
template<typename... ClassTs, typename... BaseSpecLTs>
struct hierarchy_def<class_def<ClassTs, BaseSpecLTs>...> {
static constexpr size_type num_of_classes = sizeof...(ClassTs);
};
template<template <template <typename> class> class... Ts>
struct class_tpl_list;
template<typename T, typename BL>
struct class_decl;
template<template <template <typename> class> class T, typename L>
struct class_tpl_decl;
template<typename T, typename... BaseTs>
using class_ = class_decl<T, list<BaseTs...>>;
template<
template <template <typename> class> class T,
template <template <typename> class> class... BaseTs>
using class_tpl = class_tpl_decl<T, class_tpl_list<BaseTs...>>;
template<typename... ClassDeclTs>
struct hierarchy_decl;
template<typename TL1, typename NTL2>
struct hierarchy_dissected_decl;
// -------------------------------------------------------------------------------------------------
template<typename HDecl, template <typename> class HBase>
struct transform_hierarchy_decl;
template<template <typename> class HBase, typename... CTs, typename... CBLs>
struct transform_hierarchy_decl<hierarchy_decl<class_decl<CTs, CBLs>...>, HBase> {
using type = hierarchy_def<
class_def<
CTs,
CBLs
>...
>;
};
template<template <typename> class HBase, typename L>
struct instantiate_tpl_base_list;
template<template <typename> class HBase, template <template <typename> class> class... BaseTs>
struct instantiate_tpl_base_list<HBase, class_tpl_list<BaseTs...>> {
using type = list<BaseTs<HBase>...>;
};
template<
template <typename> class HBase,
template <template <typename> class> class... CTs,
typename... CBLs>
struct transform_hierarchy_decl<hierarchy_decl<class_tpl_decl<CTs, CBLs>...>, HBase> {
using type = hierarchy_def<
class_def<
CTs<HBase>,
typename instantiate_tpl_base_list<HBase, CBLs>::type
>...
>;
};
template<
template <typename> class HBase,
template <template <typename> class> class... TCTs,
typename... TCBLs,
typename... NTCTs,
typename... NTCBLs>
struct transform_hierarchy_decl<
hierarchy_dissected_decl<
list<class_tpl_decl<TCTs, TCBLs>...>,
list<class_decl<NTCTs, NTCBLs>...>
>,
HBase
> {
using type = hierarchy_def<
class_def<
TCTs<HBase>,
typename instantiate_tpl_base_list<HBase, TCBLs>::type
>...,
class_def<
NTCTs,
NTCBLs
>...
>;
};
template<typename HDecl, template <typename> class HBase>
using transform_hierarchy_decl_t = typename transform_hierarchy_decl<HDecl, HBase>::type;
// -------------------------------------------------------------------------------------------------
template<typename HDecl, typename... ClassDeclTs>
struct extend_hierarchy_impl;
template<
typename... CTs1,
typename... CBLs1,
typename... CTs2,
typename... CBLs2>
struct extend_hierarchy_impl<
hierarchy_decl<class_decl<CTs1, CBLs1>...>,
class_decl<CTs2, CBLs2>...
> {
using type = hierarchy_decl<
class_decl<CTs1, CBLs1>...,
class_decl<CTs2, CBLs2>...
>;
};
template<
template <template <typename> class> class... TCTs1,
template <template <typename> class> class... TCTs2,
typename... TCBLs1,
typename... TCBLs2>
struct extend_hierarchy_impl<
hierarchy_decl<class_tpl_decl<TCTs1, TCBLs1>...>,
class_tpl_decl<TCTs2, TCBLs2>...
> {
using type = hierarchy_decl<
class_tpl_decl<TCTs1, TCBLs1>...,
class_tpl_decl<TCTs2, TCBLs2>...
>;
};
template<
template <template <typename> class> class... TCTs,
typename... TCBLs,
typename... NTCTs,
typename... NTCBLs>
struct extend_hierarchy_impl<
hierarchy_decl<class_tpl_decl<TCTs, TCBLs>...>,
class_decl<NTCTs, NTCBLs>...
> {
using type = hierarchy_dissected_decl<
list<class_tpl_decl<TCTs, TCBLs>...>,
list<class_decl<NTCTs, NTCBLs>...>
>;
};
template<
template <template <typename> class> class... TCTs,
typename... TCBLs,
typename... NTCTs1,
typename... NTCBLs1,
typename... NTCTs2,
typename... NTCBLs2>
struct extend_hierarchy_impl<
hierarchy_dissected_decl<
list<class_tpl_decl<TCTs, TCBLs>...>,
list<class_decl<NTCTs1, NTCBLs1>...>
>,
class_decl<NTCTs2, NTCBLs2>...
> {
using type = hierarchy_dissected_decl<
list<class_tpl_decl<TCTs, TCBLs>...>,
list<
class_decl<NTCTs1, NTCBLs1>...,
class_decl<NTCTs2, NTCBLs2>...
>
>;
};
template<
template <template <typename> class> class... TCTs1,
template <template <typename> class> class... TCTs2,
typename... TCBLs1,
typename... TCBLs2,
typename... NTCTs,
typename... NTCBLs>
struct extend_hierarchy_impl<
hierarchy_dissected_decl<
list<class_tpl_decl<TCTs1, TCBLs1>...>,
list<class_decl<NTCTs, NTCBLs>...>
>,
class_tpl_decl<TCTs2, TCBLs2>...
> {
using type = hierarchy_dissected_decl<
list<
class_tpl_decl<TCTs1, TCBLs1>...,
class_tpl_decl<TCTs2, TCBLs2>...
>,
list<class_decl<NTCTs, NTCBLs>...>
>;
};
template<
template <template <typename> class> class... TCTs,
typename... TCBLs>
struct extend_hierarchy_impl<hierarchy_decl<class_tpl_decl<TCTs, TCBLs>...>> {
using type = hierarchy_decl<
class_tpl_decl<TCTs, TCBLs>...
>;
};
template<typename HDecl, typename... ClassDeclTs>
using extend_hierarchy_t = typename extend_hierarchy_impl<HDecl, ClassDeclTs...>::type;
// -------------------------------------------------------------------------------------------------
template<typename hierarchy, typename Is>
struct hierarchy_utility;
template<typename T, typename BSL, size_type O>
struct lookup_structure {
using type = T;
using base_spec_list = BSL;
static constexpr size_type ordinal = O;
};
template<typename... ClassTs, typename... BaseSpecLTs, size_type... ClassIs>
struct hierarchy_utility<
hierarchy_def<class_def<ClassTs, BaseSpecLTs>...>,
index_sequence<ClassIs...>>
: lookup_structure<ClassTs, BaseSpecLTs, ClassIs>...
{
static constexpr size_type num_of_classes = sizeof...(ClassTs);
struct has_class_helper : type_identity<ClassTs>... {};
template<typename T>
static constexpr bool is_class_declared_v =
is_base_of_v<type_identity<remove_cv_t<T>>, has_class_helper>;
template<typename T, typename BSL, size_type O>
static lookup_structure<T, BSL, O> lookup_from_class(lookup_structure<T, BSL, O>*);
template<size_type O, typename T, typename BSL>
static lookup_structure<T, BSL, O> lookup_from_ordinal(lookup_structure<T, BSL, O>*);
template<typename T>
using base_spec_list_of_t = typename decltype(
lookup_from_class<remove_cv_t<T>>(static_cast<hierarchy_utility*>(nullptr))
)::base_spec_list;
template<typename T>
static constexpr size_type class_index_v = decltype(
lookup_from_class<remove_cv_t<T>>(static_cast<hierarchy_utility*>(nullptr))
)::ordinal;
template<size_type I>
using class_from_index_t = typename decltype(
lookup_from_ordinal<I>(static_cast<hierarchy_utility*>(nullptr))
)::type;
// -------------------------------------------------------------------
// The list returned may have duplicates.
template<typename L>
struct referenced_bases;
template<typename... Ts>
struct referenced_bases<list<Ts...>> {
using type = concat_t<
list<Ts...>,
typename referenced_bases<
base_spec_list_of_t<Ts>
>::type...
>;
};
template<typename T>
using referenced_bases_t =
typename referenced_bases<
base_spec_list_of_t<remove_cv_t<T>>
>::type;
// -------------------------------------------------------------------
template<typename Base, typename Derived>
static constexpr bool contains_base_v =
is_same_v<remove_cv_t<Base>, remove_cv_t<Derived>> ||
has_v<
referenced_bases_t<Derived>,
remove_cv_t<Base>
>;
template<typename T>
static constexpr array<bool, num_of_classes> contains_base_survey = {{
contains_base_v<T, ClassTs>...
}};
// -------------------------------------------------------------------
// Topmost bases are those with zero bases themselves.
template<typename L>
struct all_paths_to_topmost_bases_impl;
template<typename... Ts>
struct all_paths_to_topmost_bases_impl<list<Ts...>> {
template<typename... Trajectory>
using type = typename ternary<sizeof...(Ts) != 0>::template type<
concat_t<
typename all_paths_to_topmost_bases_impl<
base_spec_list_of_t<Ts>
>::template type<Trajectory..., Ts>...
>,
list<list<Trajectory...>>
>;
};
template<typename T>
using all_paths_to_topmost_bases_t =
typename all_paths_to_topmost_bases_impl<
base_spec_list_of_t<T>
>::template type<remove_cv_t<T>>;
// -------------------------------------------------------------------
// The last boolean parameter is there because C++ Core DR 727 is
// not (yet) implemented in GCC.
template<typename T, bool B>
struct path_to_any_topmost_base_impl;
template<typename FT, typename... Ts, bool B>
struct path_to_any_topmost_base_impl<list<FT, Ts...>, B> {
template<typename... Trajectory>
using type = typename path_to_any_topmost_base_impl<
base_spec_list_of_t<FT>,
false
>::template type<Trajectory..., FT>;
};
template<bool B>
struct path_to_any_topmost_base_impl<list<>, B> {
template<typename... Trajectory>
using type = list<Trajectory...>;
};
template<typename T>
using path_to_any_topmost_base_t = typename path_to_any_topmost_base_impl<
base_spec_list_of_t<T>,
false
>::template type<remove_cv_t<T>>;
// -------------------------------------------------------------------
// Note, that for a single inheritance inhierarchy, there is only one
// topmost base for any class in the hierarchy. The last bool parameter
// is there because C++ Core DR 727 is not (yet) implemented in GCC.
template<typename T, bool B>
struct any_topmost_base_impl;
template<typename FT, typename... R, bool B>
struct any_topmost_base_impl<list<FT, R...>, B> {
template<typename Prev>
using type = typename any_topmost_base_impl<
base_spec_list_of_t<FT>,
false
>::template type<FT>;
};
template<bool B>
struct any_topmost_base_impl<list<>, B> {
template<typename Prev>
using type = Prev;
};
template<typename T>
using any_topmost_base_t = typename any_topmost_base_impl<
base_spec_list_of_t<T>,
false
>::template type<remove_cv_t<T>>;
struct casting;
};
template<typename hierarchy>
using hierarchy_utility_t = hierarchy_utility<
hierarchy,
make_index_sequence<hierarchy::num_of_classes>
>;
// -------------------------------------------------------------------------------------------------
template<typename T, typename... Ts1, typename... Ts2>
inline constexpr decltype(auto) native_sequential_upcast_impl(T&& d, list<Ts1...>*, list<Ts2...>*) {
static_assert((is_base_of_v<Ts2, Ts1> && ...), "invalid path");
using T1 = nth_type_t<0, Ts1...>;
match_cv_t<T1, void>* p = addressof((T1&)(d));
((p = addressof((Ts2&)(*static_cast<Ts1*>(p)))), ...);
using tn = match_cv_t<T1, nth_type_t<sizeof...(Ts1)-1, Ts1...>>;
return static_cast<match_ref_t<T&&, tn>>(*static_cast<tn*>(p));
}
template<typename T, typename F, typename... R>
inline constexpr decltype(auto) native_sequential_upcast(T&& d, list<F, R...>* L1) {
static_assert(sizeof(remove_reference_t<T>) >= 0, "source must be of complete type");
using LT1 = list<
match_cv_t<remove_reference_t<T>, F>,
match_cv_t<remove_reference_t<T>, R>...
>;
using LT2 = list<
match_cv_t<remove_reference_t<T>, R>...,
match_cv_t<remove_reference_t<T>, nth_type_t<sizeof...(R), F, R...>>
>;
return native_sequential_upcast_impl(static_cast<T&&>(d),
static_cast<LT1*>(nullptr),
static_cast<LT2*>(nullptr));
}
// -------------------------------------------------------------------------------------------------
enum class mode
{
barebones,
standard
};
template<bool, size_type N, mode tim, typename derived, typename derived_base>
class type_info_bag;
template<typename derived_base, mode m>
struct hy_deduction_helper {
static constexpr mode tim = m;
using hierarchy = typename derived_base::_cavi_hierarchy;
using base = derived_base;
};
template<typename derived, bool B, size_type N, mode tim, typename derived_base>
inline hy_deduction_helper<derived_base, tim>
deduce_hierarchy_helper_func(type_info_bag<B, N, tim, derived, derived_base>*);
template<typename derived>
struct deduce_hierarchy_impl {
static_assert(sizeof(derived) >= 0, "incomplete type");
using type = decltype(
deduce_hierarchy_helper_func<remove_cv_t<derived>>(
static_cast<remove_cv_t<derived>*>(nullptr)
)
);
};
template<typename derived>
using deduce_hierarchy_t = typename deduce_hierarchy_impl<derived>::type::hierarchy;
template<typename derived>
inline constexpr mode deduce_mode_v = deduce_hierarchy_impl<derived>::type::tim;
template<typename derived>
using deduce_base_t = typename deduce_hierarchy_impl<derived>::type::base;
// -------------------------------------------------------------------------------------------------
template<size_type N>
using id_integral_t =
typename ternary<N == static_cast<unsigned char>(N)>::template type<
unsigned char,
typename ternary<N == static_cast<unsigned short>(N)>::template type<
unsigned short,
typename ternary<N == static_cast<unsigned long>(N)>::template type<
unsigned long,
unsigned long long
>
>
>;
template<size_type N_of_classes_in_hy, mode>
struct type_info;
template<size_type N>
struct type_info<N, mode::barebones> {
id_integral_t<N> _cavi_type_id;
constexpr type_info(void* ptr, id_integral_t<N> tid) :
_cavi_type_id(tid) {}
};
template<size_type N>
struct type_info<N, mode::standard> {
void* _cavi_instance_ptr;
id_integral_t<N> _cavi_type_id;
constexpr type_info(void* ptr, id_integral_t<N> tid) :
_cavi_instance_ptr(ptr), _cavi_type_id(tid) {}
};
// -------------------------------------------------------------------------------------------------
template<bool, size_type N_of_classes_in_hy, mode, typename derived, typename derived_base>
class type_info_bag {
public:
constexpr type_info_bag() {}
};
template<size_type N, mode tim, typename derived, typename derived_base>
class type_info_bag<true, N, tim, derived, derived_base> : private type_info<N, tim> {
public:
constexpr type_info_bag() :
type_info<N, tim>(
(derived*)this,
static_cast<id_integral_t<N>>(
hierarchy_utility_t<deduce_hierarchy_t<derived>>::template class_index_v<derived>
)
)
{
// both to validate the cast above
static_assert(sizeof(derived) >= 0,
"derived type is incomplete");
static_assert(is_base_of_v<type_info_bag, derived>,
"class does not inherit cavi base");
}
};
template<typename hierarchy, mode tim, typename derived, typename derived_base>
using type_info_bag_t = type_info_bag<
length_v<
typename hierarchy_utility_t<hierarchy>::template base_spec_list_of_t<derived>
> == 0,
hierarchy::num_of_classes,
tim,
derived,
derived_base
>;
// -------------------------------------------------------------------------------------------------
template<typename derived, typename id_type, typename... bases>
inline constexpr void set_type_info_from_path(derived* d, id_type id, list<bases...>* path)
{
auto& casted = native_sequential_upcast(*d, path);
using hierarchy = deduce_hierarchy_t<derived>;
constexpr mode tim = deduce_mode_v<derived>;
using ti_type = type_info<hierarchy::num_of_classes, tim>;
using last = remove_reference_t<decltype(casted)>;
static_assert(is_base_of_v<ti_type, last>,
"a class does not inherit from cavi base");
ti_type& ti = (ti_type&)casted;
ti._cavi_type_id = id;
if constexpr(tim != mode::barebones)
ti._cavi_instance_ptr = d;
}
template<mode tim, size_type N>
inline constexpr void set_instance_ptr(type_info<N, tim>& ti, void* ptr) {
if constexpr(tim != mode::barebones)
ti._cavi_instance_ptr = ptr;
}
template<typename derived, typename id_type, typename... Paths>
inline constexpr void set_type_info_multiple(derived* d, id_type id, list<Paths...>*) {
(set_type_info_from_path(d, id, static_cast<Paths*>(nullptr)), ...);
}
// -------------------------------------------------------------------------------------------------
#define CAVI_MAKE_FRIEND template<typename> friend struct cavi::deduce_hierarchy_impl;
#define CAVI_INTERNAL_BASE_IMPL(hierarchydcl, base_name, base_mode) \
template<typename derived> \
class base_name : public cavi::type_info_bag_t< \
cavi::transform_hierarchy_decl_t<hierarchydcl, base_name>, \
base_mode, \
derived, \
base_name<derived> \
> { \
friend derived; \
friend cavi::hy_deduction_helper<base_name<derived>, base_mode>; \
\
using _cavi_hierarchy = cavi::transform_hierarchy_decl_t<hierarchydcl, base_name>; \
static constexpr cavi::mode _cavi_tim = base_mode; \
\
constexpr base_name() noexcept : \
cavi::type_info_bag_t< \
cavi::transform_hierarchy_decl_t<hierarchydcl, base_name>, \
base_mode, \
derived, \
base_name<derived> \
>() { \
using hutil = cavi::hierarchy_utility_t<_cavi_hierarchy>; \
using ti_type = cavi::type_info<_cavi_hierarchy::num_of_classes, base_mode>; \
using id_type = cavi::id_integral_t<_cavi_hierarchy::num_of_classes>; \
\
static_assert(hutil::template is_class_declared_v<derived>, \
"class is not declared in the hierarchy"); \
\
derived* d = (derived*)(this); \
cavi::size_type type_index = hutil::template class_index_v<derived>; \
id_type type_id = static_cast<id_type>(type_index); \
\
static_assert(cavi::is_base_of_v<ti_type, derived>, \
"a class does not inherit from cavi base"); \
\
if constexpr(cavi::is_pointer_explicit_cast_ok_v<derived*, ti_type*>) { \
ti_type& ti = (ti_type&)(*d); \
ti._cavi_type_id = type_id; \
cavi::set_instance_ptr(ti, d); \
} else { \
/* multiple instances of ti_type - set them all */ \
using paths = typename hutil::template all_paths_to_topmost_bases_t<derived>; \
cavi::set_type_info_multiple(d, type_id, static_cast<paths*>(nullptr)); \
} \
} \
\
public: \
constexpr base_name(const base_name&) noexcept : base_name() {} \
constexpr base_name(base_name&&) noexcept : base_name() {} \
base_name& operator = (const base_name&) noexcept {} \
base_name& operator = (base_name&&) noexcept {} \
~base_name() noexcept = default; \
};
#define CAVI_DEF_BAREBONES_BASE(hierarchydcl, base_name) \
CAVI_INTERNAL_BASE_IMPL(hierarchydcl, base_name, cavi::mode::barebones)
#define CAVI_DEF_STANDARD_BASE(hierarchydcl, base_name) \
CAVI_INTERNAL_BASE_IMPL(hierarchydcl, base_name, cavi::mode::standard)
// -------------------------------------------------------------------------------------------------
#define CAVI_REPEAT_NUM_HANDLER_4(handler, n, a1, a2) \
handler((n + 0), a1, a2) \
handler((n + 1), a1, a2) \
handler((n + 2), a1, a2) \
handler((n + 3), a1, a2) \
#define CAVI_REPEAT_NUM_HANDLER_16(handler, n, a1, a2) \
CAVI_REPEAT_NUM_HANDLER_4(handler, (n + 0), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_4(handler, (n + 4), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_4(handler, (n + 8), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_4(handler, (n + 12), a1, a2)
#define CAVI_REPEAT_NUM_HANDLER_64(handler, n, a1, a2) \
CAVI_REPEAT_NUM_HANDLER_16(handler, (n + 0), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_16(handler, (n + 16), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_16(handler, (n + 32), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_16(handler, (n + 48), a1, a2)
#define CAVI_REPEAT_NUM_HANDLER_256(handler, n, a1, a2) \
CAVI_REPEAT_NUM_HANDLER_64(handler, (n + 0), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_64(handler, (n + 64), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_64(handler, (n + 128), a1, a2) \
CAVI_REPEAT_NUM_HANDLER_64(handler, (n + 192), a1, a2)
// -------------------------------------------------------------------------------------------------
template<template <typename> class HBase>
size_type hierarchy_verified();
template<typename B>
struct call_hierarchy_verified_helper;
template<typename T, template <typename> class HBase>
struct call_hierarchy_verified_helper<HBase<T>> {
static void func() {
hierarchy_verified<HBase>();
}
};
template<typename T>
inline void call_hierarchy_verified() {
using derived_base = deduce_base_t<T>;
call_hierarchy_verified_helper<derived_base>::func();
}
template<typename T, mode hmode, size_type I = static_cast<size_type>(-1)>
struct cast_exports {};
template<typename T>
struct cast_exports<T, mode::barebones, static_cast<size_type>(-1)> {
static T& cast_to_mdt(const volatile void* topmost_base_obj);
};
template<typename T>
struct cast_exports<T, mode::standard, static_cast<size_type>(-1)> {
static void* cast_to_db(const volatile T& from, size_type to_id);
static bool is_db_public(size_type to_id);
};
// -------------------------------------------------------------------------------------------------
template<typename T>
inline const auto& get_type_info(const T& obj) {
using hierarchy = deduce_hierarchy_t<T>;
constexpr mode tim = deduce_mode_v<T>;
using deduced_ti_base = type_info<hierarchy::num_of_classes, tim>;
using hutil = hierarchy_utility_t<hierarchy>;
using ti_type = typename ternary<is_volatile_v<T>>::template type<
const volatile deduced_ti_base,
const deduced_ti_base
>;
static_assert(is_base_of_v<deduced_ti_base, T>,
"a class does not inherit from cavi base");
if constexpr(is_pointer_explicit_cast_ok_v<const T*, ti_type*>) {
const ti_type& ti = (const ti_type&)obj;
return ti;
}
else {
// has multiple instances of ti_type - pick any one of them
using path = typename hutil::template path_to_any_topmost_base_t<T>;
auto& casted = native_sequential_upcast(obj, static_cast<path*>(nullptr));
using last = remove_reference_t<decltype(casted)>;
static_assert(is_base_of_v<deduced_ti_base, last>,
"a class does not inherit from cavi base");
const ti_type& ti = (const ti_type&)casted;
return ti;
}
}
// -------------------------------------------------------------------------------------------------
template<mode, typename O>
struct instance_ptr_of {
template<size_type dummy>
static void* f(O&& obj) {
return get_type_info(static_cast<O&&>(obj))._cavi_instance_ptr;
}
};
template<typename O>
struct instance_ptr_of<mode::barebones, O> {
template<size_type MDT_INDEX>
static void* f(O&& obj) {
using O_wo_ref = remove_reference_t<O>;
using hutil = hierarchy_utility_t<deduce_hierarchy_t<O_wo_ref>>;
using MDT = typename hutil::template class_from_index_t<MDT_INDEX>;
using topmost_base_type = typename hutil::template any_topmost_base_t<O_wo_ref>;
static_assert(sizeof(O_wo_ref) >= 0, "incomplete type");
static_assert(is_base_of_v<topmost_base_type, O_wo_ref>,
"base class specified in hierarchy is not a base class");
auto* ptr = addressof((const volatile topmost_base_type&)(obj));
return addressof(cast_exports<MDT, mode::barebones>::cast_to_mdt(ptr));
}
};
}; // namespace cavi
#endif
|
9ecb896c1082df0cb0361eb78b20eb12c7bdfde6
|
e0904d35f0b89fed8ebdeb6e08864c0208006954
|
/ProcessLib/Output/SecondaryVariable.cpp
|
b19e9370943c5083ac50fb7424b58e29a029b531
|
[
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
ufz/ogs
|
e3f7b203ac960eeed81c3ad20e743b2ee2f4753e
|
073d0b9820efa5149578259c0137999a511cfb4f
|
refs/heads/master
| 2023-08-31T07:09:48.929090
| 2023-08-30T09:24:09
| 2023-08-30T09:24:09
| 1,701,384
| 125
| 259
|
BSD-3-Clause
| 2021-04-22T03:28:27
| 2011-05-04T14:09:57
|
C++
|
UTF-8
|
C++
| false
| false
| 2,306
|
cpp
|
SecondaryVariable.cpp
|
/**
* \file
* \copyright
* Copyright (c) 2012-2023, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "SecondaryVariable.h"
namespace ProcessLib
{
void SecondaryVariableCollection::addNameMapping(
std::string const& internal_name, std::string const& external_name)
{
// TODO check for missing secondary vars.
// TODO check primary vars, too
BaseLib::insertIfKeyUniqueElseError(
_map_external_to_internal, external_name, internal_name,
"Secondary variable names must be unique.");
}
void SecondaryVariableCollection::addSecondaryVariable(
std::string const& internal_name, SecondaryVariableFunctions&& fcts)
{
if (!_configured_secondary_variables
.emplace(std::make_pair(
internal_name,
SecondaryVariable{internal_name /* TODO change */,
std::move(fcts)}))
.second)
{
OGS_FATAL(
"The secondary variable with internal name `{:s}' has already been "
"set up.",
internal_name);
}
}
std::map<std::string, std::string>::const_iterator
SecondaryVariableCollection::begin() const
{
return _map_external_to_internal.cbegin();
}
std::map<std::string, std::string>::const_iterator
SecondaryVariableCollection::end() const
{
return _map_external_to_internal.cend();
}
SecondaryVariable const& SecondaryVariableCollection::get(
std::string const& external_name) const
{
auto const it = _map_external_to_internal.find(external_name);
if (it == _map_external_to_internal.cend())
{
OGS_FATAL(
"A secondary variable with external name '{:s}' has not been set "
"up.",
external_name);
}
auto const& internal_name = it->second;
auto const it2 = _configured_secondary_variables.find(internal_name);
if (it2 == _configured_secondary_variables.end())
{
OGS_FATAL(
"A secondary variable with internal name '{:s}' has not been set "
"up.",
internal_name);
}
return it2->second;
}
} // namespace ProcessLib
|
784b1aaa62fef462b5a75fbd019a88e81ae76c87
|
29af718d33105bceddd488326e53dab24e1014ef
|
/TestSystem/messages/TestLevel.hpp
|
d116b6e5af66f5424d217b9a7d33d5501c72a691
|
[] |
no_license
|
OKullmann/oklibrary
|
d0f422847f134705c0cd1eebf295434fe5ffe7ed
|
c578d0460c507f23b97329549a874aa0c0b0541b
|
refs/heads/master
| 2023-09-04T02:38:14.642785
| 2023-09-01T11:38:31
| 2023-09-01T11:38:31
| 38,629
| 21
| 64
| null | 2020-10-30T17:13:04
| 2008-07-30T18:20:06
|
C++
|
UTF-8
|
C++
| false
| false
| 3,140
|
hpp
|
TestLevel.hpp
|
// Oliver Kullmann, 15.2.2006 (Swansea)
/* Copyright 2006 - 2007 Oliver Kullmann
This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation and included in this library; either version 3 of the
License, or any later version. */
/*!
\file TestSystem/messages/TestLevel.hpp
\brief Message objects to explain the test levels
*/
#ifndef TESTLEVELEXPLANATIONS_uYYtr5
#define TESTLEVELEXPLANATIONS_uYYtr5
#include <OKlib/Programming/Messages/MessagesMain.hpp>
#include <OKlib/Programming/Messages/LineHandling.hpp>
#include <OKlib/TestSystem/TestFondement.hpp>
namespace OKlib {
namespace TestSystem {
namespace messages {
OKLIB_USING_MESSAGES
/*!
\class TestLevelDescriptions
\brief Output of test-level descriptions
Attention: The const-reference to the level object must not be bound to a temporary!
(This leads to undefined behaviour, but compilers usually don't catch this.)
\todo How to handle that sometimes we may want to start with "Test level" instead of "test level" ?
*/
struct TestLevelDescriptions : ::OKlib::Messages::MessagesPrePost {
OKLIB_MESSAGES_PRINT
explicit TestLevelDescriptions(const ::OKlib::TestSystem::TestLevel& lev) : lev(lev) {}
struct dispatch : ::OKlib::TestSystem::VisitorTestLevel {
std::ostream& out;
const char* const b; const char* const f; const char* const e;
dispatch(std::ostream& out, const char* const b, const char* const f, const char* const e) : out(out), b(b), f(f), e(e) {}
void operator()(::OKlib::TestSystem::Basic) const { out << b; }
void operator()(::OKlib::TestSystem::Full) const { out << f; }
void operator()(::OKlib::TestSystem::Extensive) const { out << e; }
};
void print(std::ostream& out, L<en_GB>, S<Basic>) const {
l_start(out) << "test level = ";
lev(dispatch(out, "Basic test level", "Full test level", "Extensive test level"));
}
void print(std::ostream& out, L<en_GB>, S<Full>) const {
l_start(out) << "test level = ";
lev(dispatch(out, "Basic test level (used for permanent testing)", "Full test level (for the daily test)", "Extensive test level (for the weekly test)"));
}
void print(std::ostream& out, L<de_DE>, S<Basic>) const {
l_start(out) << "Testniveau = ";
lev(dispatch(out, "Basis-Testniveau (\"basic\")", "Volles Testniveau (\"full\")", "Umfangreiches Testniveau (\"extensive\")"));
}
void print(std::ostream& out, L<de_DE>, S<Full>) const {
l_start(out) << "Testniveau = ";
lev(dispatch(out, "Basis-Testniveau (\"basic\"; für das laufende Testen)", "Volles Testniveau (\"full\"; z.B. für den täglichen Test)", "Umfangreiches Testniveau (\"extensive\"; z.B. für den wöchentlichen Test)"));
}
private :
const ::OKlib::TestSystem::TestLevel& lev;
};
}
}
}
#endif
|
b00857519f39081d7a938ecff545d2eb954c4ed4
|
49ed10fa6bf2b585daf6ac66dc5da0042ac3d130
|
/main.cpp
|
bd04cadf036128cf60a5661b041feeb68353e3b2
|
[] |
no_license
|
eprana/Zipix
|
6b0925d3a59d15b38d68067b6209e221d9765943
|
c0a0e52ef495709d6074ab0daae02d65a64def29
|
refs/heads/master
| 2020-05-18T18:56:29.856635
| 2014-01-28T07:29:07
| 2014-01-28T07:29:07
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 8,349
|
cpp
|
main.cpp
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <glm/glm.hpp>
#include <glm/gtc/random.hpp>
#include "Game.hpp"
#include "renderer/WindowManager.hpp"
#include "ConstantForce.hpp"
#include "PolygonForce.hpp"
#include "HookForce.hpp"
#include "BrakeForce.hpp"
#include "GraphBrakeForce.hpp"
#include "GraphHookForce.hpp"
//FMOD
#include "fmod.h"
#include "fmod_errors.h"
#include <vector>
static const Uint32 WINDOW_WIDTH = 1024;
static const Uint32 WINDOW_HEIGHT = 1024;
using namespace imac3;
int main() {
WindowManager wm(WINDOW_WIDTH, WINDOW_HEIGHT, "ZIPIX");
wm.setFramerate(30);
// FMOD
FMOD_SYSTEM *system;
/* Création et initialisation d'un objet système */
FMOD_System_Create(&system);
FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL);
FMOD_SOUND* background = NULL;
FMOD_SOUND* firework = NULL;
FMOD_RESULT check;
check = FMOD_System_CreateSound(system, "../music/firework_explode_and_crackle.mp3", FMOD_CREATESAMPLE, 0, &firework);
if (check != FMOD_OK)
{
fprintf(stderr, "Impossible de lire le fichier firework_explode_and_crackle.mp3\n");
exit(EXIT_FAILURE);
}
check = FMOD_System_CreateSound(system, "../music/Timer.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &background);
if (check != FMOD_OK)
{
fprintf(stderr, "Impossible de lire le fichier Timer.mp3\n");
exit(EXIT_FAILURE);
}
FMOD_CHANNEL *backgroundChannel = NULL;
FMOD_CHANNEL *fireworkChannel = NULL;
FMOD_System_GetChannel(system, 0, &backgroundChannel);
FMOD_System_GetChannel(system, 1, &fireworkChannel);
FMOD_Sound_SetLoopCount(background, -1);
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, background, 0, &backgroundChannel);
// Time
time_t beginTime;
time_t currentTime;
time(&beginTime);
// Managers and Renderer
ParticleRenderer2D renderer;
ParticleManager snakeManager;
snakeManager.setHeadColor(glm::vec3(0.4f, 0.8f, 0.3f));
ParticleManager redManager;
redManager.setHeadColor(glm::vec3(0.9f, 0.4f, 0.3f));
ParticleManager blueManager;
blueManager.setHeadColor(glm::vec3(0.2f, 0.4f, 0.9f));
ParticleManager foodManager;
ParticleManager bonusManager;
ParticleManager fireworkManager;
ParticleManager autoManager;
// Graph Forces
GraphHookForce graphHook = GraphHookForce(1.f, 0.15f/4.f);
GraphBrakeForce graphBrake = GraphBrakeForce(0.3f, 10.f); // 0.5 = viscosité max
GraphHookForce redGraphHook = GraphHookForce(1.f, 0.15f/4.f);
GraphBrakeForce redGraphBrake = GraphBrakeForce(0.3f, 0.0001f);
GraphHookForce blueGraphHook = GraphHookForce(1.f, 0.15f/4.f);
GraphBrakeForce blueGraphBrake = GraphBrakeForce(0.3f, 0.0001f);
// Box
Polygon box = buildBox(glm::vec3(1.f, 1.f, 1.f), glm::vec2(-1.f, -1.f), 2, 2, true);
// // Ajout des particules
int id = foodManager.addRandomParticle(1);
bonusManager.addParticle(1.5f, glm::vec2(0.5, 0.5), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
bonusManager.addParticle(1.5f, glm::vec2(-0.2, 0.6), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
bonusManager.addParticle(1.5f, glm::vec2(0.8, -0.7), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
bonusManager.addParticle(1.5f, glm::vec2(-0.7, -0.5), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
bonusManager.addParticle(1.5f, glm::vec2(0.3, -0.1), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
// Copy the food to the autoManager
copyParticle(foodManager, autoManager, id);
// Forces
ConstantForce mg(glm::vec2(0.f, -0.005));
// LeapfrogSolver
LeapfrogSolver leapfrog;
PolygonForce boxForce(box, 1.5f, leapfrog);
// Snake's creation
ParticleGraph snakeGraph = createString(glm::vec2(0.f, 0.0f), glm::vec2(0.f, -0.15f), glm::vec3(0.2f, 0.6f, 0.2f), glm::vec3(0.4f, 0.8f, 0.3f), 4.f, snakeManager);
ParticleGraph redGraph = createString(glm::vec2(0.f, 0.2f), glm::vec2(0.15f, 0.2f), glm::vec3(0.9f, 0.2f, 0.2f), glm::vec3(0.9f, 0.4f, 0.3f), 4.f, redManager);
ParticleGraph blueGraph = createString(glm::vec2(0.f, -0.2f), glm::vec2(-0.15f, -0.2f), glm::vec3(0.2f, 0.2f, 0.6f), glm::vec3(0.2f, 0.4f, 0.9f), 4.f, blueManager);
copyParticle(snakeManager, autoManager, 0);
copyParticle(redManager, autoManager, 0);
copyParticle(blueManager, autoManager, 0);
// Variables
int score = 0;
int bonus = 0;
// Temps s'écoulant entre chaque frame
float dt = 0.f;
bool done = false;
while(!done) {
time(¤tTime);
wm.startMainLoop();
// Renderer
renderer.clear();
// Draw particles
foodManager.drawParticles(renderer);
snakeManager.drawParticles(renderer);
redManager.drawParticles(renderer);
blueManager.drawParticles(renderer);
fireworkManager.drawParticles(renderer);
bonusManager.drawParticles(renderer);
mg.apply(fireworkManager);
// Mise à jour du graph autoGraph
updateParticle(snakeManager, 0, autoManager, 1);
updateParticle(redManager, 0, autoManager, 2);
updateParticle(blueManager, 0, autoManager, 3);
// Force attractive
addAttractiveForce(foodManager, snakeManager);
addAttractiveForce(foodManager, redManager);
addAttractiveForce(foodManager, blueManager);
// Forces
graphHook.setGraph(&snakeGraph);
graphBrake.setGraph(&snakeGraph);
redGraphHook.setGraph(&redGraph);
redGraphBrake.setGraph(&redGraph);
blueGraphHook.setGraph(&blueGraph);
blueGraphBrake.setGraph(&blueGraph);
// Simulation
if(dt != 0) {
//Bonus
if(difftime(currentTime, beginTime) == 10) {
beginTime = currentTime;
time(¤tTime);
addBonus(bonusManager);
bonus++;
}
// Snake - Food
if( checkFoodCollision(snakeGraph, snakeManager, foodManager, fireworkManager, 0.05f, 0) != -1
|| checkFoodCollision(redGraph, redManager, foodManager, fireworkManager, 0.05f, 0) != -1
|| checkFoodCollision(blueGraph, blueManager, foodManager, fireworkManager, 0.05f, 0) != -1) {
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, firework, 0, &fireworkChannel);
updateParticle(foodManager, 0, autoManager, 0);
bonus++;
}
// Apply forces
graphBrake.setDt(dt);
redGraphBrake.setDt(dt);
blueGraphBrake.setDt(dt);
boxForce.setDt(dt);
boxForce.apply(snakeManager);
boxForce.apply(redManager);
boxForce.apply(blueManager);
graphHook.apply(snakeManager);
graphBrake.apply(snakeManager);
redGraphHook.apply(redManager);
redGraphBrake.apply(redManager);
blueGraphHook.apply(blueManager);
blueGraphBrake.apply(blueManager);
addRepulsiveForce(bonusManager, snakeManager);
addRepulsiveForce(bonusManager, redManager);
addRepulsiveForce(bonusManager, blueManager);
// Leapfrog solver
leapfrog.solve(snakeManager, dt);
leapfrog.solve(autoManager, dt);
leapfrog.solve(redManager, dt);
leapfrog.solve(blueManager, dt);
leapfrog.solve(fireworkManager, dt);
leapfrog.solve(bonusManager, dt);
}
// Gestion des evenements
SDL_Event e;
while(wm.pollEvent(e)) {
switch(e.type) {
default:
break;
case SDL_QUIT:
//FMOD
/* On libère le son et on ferme et libère l'objet système */
FMOD_Sound_Release(background);
FMOD_Sound_Release(firework);
FMOD_System_Close(system);
FMOD_System_Release(system);
done = true;
break;
}
}
// Mise à jour de la fenêtre
dt = wm.update();
}
return EXIT_SUCCESS;
}
|
bb3bffc18f08975d66ab3b99f14b2d3592ddf7d2
|
75f26c2678a8c16899ae58a07879a7e3c6d2d36a
|
/Kernel/tRareSaveStack.h
|
5bb7e3ca2b82de5b4626333cbba42871651af088
|
[] |
no_license
|
tweag/factplusplus
|
ce94e4c87e52e9f1353e34043319592bed2d7bb9
|
d7f377351d82ea5243262538e43ddc4f0312ecdf
|
refs/heads/master
| 2021-05-01T04:20:52.485504
| 2016-09-16T07:06:52
| 2016-09-16T07:06:52
| 75,384,013
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,417
|
h
|
tRareSaveStack.h
|
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
Copyright (C) 2015-2016 Dmitry Tsarkov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TRARESAVESTACK_H
#define TRARESAVESTACK_H
#include <vector>
#include "globaldef.h"
#include "tRestorer.h"
/**
* Stack for Saving/Restoring rarely changing information.
* Uses self-contained Restorer as a way to update state of object.
*/
class TRareSaveStack
{
protected: // typedefs
/// vector of restorers
typedef std::vector<TRestorer*> TBaseType;
protected: // members
/// heap of saved objects
TBaseType Base;
/// current level
unsigned int curLevel;
public: // interface
/// empty c'tor: stack will most likely be empty
TRareSaveStack ( void ) : curLevel(InitBranchingLevelValue) {}
/// d'tor
~TRareSaveStack ( void ) { clear(); }
// stack operations
/// inclrement current level
void incLevel ( void ) { ++curLevel; }
/// check that stack is empty
bool empty ( void ) const { return Base.empty(); }
/// add a new object to the stack
void push ( TRestorer* p )
{
p->setLevel(curLevel);
Base.push_back(p);
}
/// get all object from the top of the stack with levels >= LEVEL
void restore ( unsigned int level )
{
curLevel = level;
while ( !Base.empty() )
{
TRestorer* cur = Base.back();
if ( cur->level() <= level )
break;
// need to restore: restore last element, remove it from stack
cur->restore();
delete cur;
Base.pop_back();
}
}
/// clear stack
void clear ( void )
{
for ( TBaseType::iterator p = Base.begin(), p_end = Base.end(); p < p_end; ++p )
delete *p;
Base.clear();
curLevel = InitBranchingLevelValue;
}
}; // TRareSaveStack
#endif
|
e2ed3ddb589e59ca80215b1d56485b361d14076b
|
883a4d2e9e3216e314cbcac4809b193cd8302eac
|
/RTOS/process_b.h
|
6377e072af8f71054d5c8e70af860aec46986b8f
|
[] |
no_license
|
ycechung/uni_code
|
1a6da58f93b0a22fc797f3b1ea9f4c052725488e
|
70b5a6a3e86116d5d7af5f71c33a58c1640e143f
|
refs/heads/master
| 2020-06-29T23:21:40.073931
| 2012-03-10T02:43:21
| 2012-03-10T02:43:21
| 3,676,563
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 194
|
h
|
process_b.h
|
/**
Header file for process b.
**/
#ifndef PROCESS_B_H
#define PROCESS_B_H
#ifdef _WIN32
#pragma once
#endif
#include "rtx.h"
class ProcessB : private Process
{
PROCESS_DECLARE()
};
#endif
|
9ba99eec301aac8b30b767b89e6fdc97025db349
|
e94409baa6864db04a7785fbd7346c9e95dc85d5
|
/sources/sim/fsim/E14Fsim/src/E14FsimBHPVModule.cc
|
9e072acfe2240daa0e9581d80098f1b61c3bda6a
|
[] |
no_license
|
laerad84/e14
|
3d9be7b6712df3534dcba2132a6f9e3ed8b517fc
|
89875a124b1d7bb960b5919e75747c90bf72996d
|
refs/heads/master
| 2016-09-16T00:46:33.493744
| 2012-06-18T06:46:57
| 2012-06-18T06:46:57
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,743
|
cc
|
E14FsimBHPVModule.cc
|
#include "E14Fsim/E14FsimBHPVModule.h"
#include "E14Fsim/E14FsimPersistencyManager.h"
#include "E14Fsim/E14FsimVeto.h"
#include "GsimData/GsimGenParticleData.h"
#include "GsimData/GsimDetectorEventData.h"
#include "TMath.h"
#include <cmath>
E14FsimBHPVModule::E14FsimBHPVModule()
: E14FsimAnalysisModule()
{
m_detID=9;
}
E14FsimBHPVModule::~E14FsimBHPVModule()
{
;
}
void E14FsimBHPVModule::processEvent()
{
double BHCVineff = 0.005;
int VetoID = m_detID+1;
GsimDetectorEventData* detData
=E14FsimPersistencyManager::getPersistencyManager()->getDetectorEventData(m_detID);
TClonesArray* detHitArray = detData->hits;
int nHit =detHitArray->GetEntries();
for (int j=0; j<nHit; j++){
GsimDetectorHitData* aHit = (GsimDetectorHitData*)(detHitArray)->At(j);
double Mome = aHit->p.Mag();
int PID = aHit->pid;
E14FsimVeto* veto = new E14FsimVeto();
if(PID == 22){ // for gamma
double ineffi=catcherIneff(Mome);
veto->setIneffi(ineffi);
}
else if (PID == 11 || PID == -11 || PID == 13 || PID == -13 ){ // for e and mu
veto->setIneffi(BHCVineff);
}
else if (PID == 211 || PID == -211 ){
veto->setIneffi(BHCVineff);
} else {
veto->setIneffi(1.);
}
veto->setDetID(VetoID);
veto->setPID(PID);
veto->setMome(aHit->p.x(),
aHit->p.y(),
aHit->p.z());
veto->setPos(aHit->r.x(),
aHit->r.y(),
aHit->r.z());
s_vetoList.push_back(veto);
}
}
double E14FsimBHPVModule::catcherIneff(double Egamma){
Egamma /= 1000; //MeV to GeV
// double ineff = 2e-3 + exp(1.13 - 3.67*Egamma);
double ineff = 0.001 + exp(0.5745 - 8.631*Egamma);
ineff =TMath::Min(1.0,ineff);
return(ineff);
}
|
40d2dbd29f49c04dbb4bb03cf2bb0029dd641ff6
|
b7ee9ac14d6981e18fa1b19214366878a4884a42
|
/Projects/Skylicht/Engine/Source/Tween/CTweenVector2df.h
|
da5a91092eab6bc897db41b49cc150dfa5a41baa
|
[
"MIT"
] |
permissive
|
skylicht-lab/skylicht-engine
|
89d51b4240ca6ed5a7f15b413df5711288580e9e
|
ff0e875581840efd15503cdfa49f112b6adade98
|
refs/heads/master
| 2023-09-01T02:23:45.865965
| 2023-08-29T08:21:41
| 2023-08-29T08:21:41
| 220,988,542
| 492
| 46
|
MIT
| 2023-06-05T10:18:45
| 2019-11-11T13:34:56
|
C++
|
UTF-8
|
C++
| false
| false
| 464
|
h
|
CTweenVector2df.h
|
#pragma once
#include "CTween.h"
namespace Skylicht
{
class CTweenVector2df : public CTween
{
protected:
core::vector2df m_value;
public:
CTweenVector2df(const core::vector2df& begin, const core::vector2df& end, float duration);
virtual ~CTweenVector2df();
virtual void updateValue();
void setBegin(const core::vector2df& begin);
void setEnd(const core::vector2df& end);
const core::vector2df& getValue()
{
return m_value;
}
};
}
|
561dd7ff87e2c676624de6905a6d2746878e1edb
|
b8c6b9a4b3a5f7fc317e3aa8d68d18e47182e2e1
|
/DataStructureAndAlgorithmTest/002 - HamiltonianCycle.cpp
|
bfe1fd72c7bd529e986e4f5554703f806a31f247
|
[] |
no_license
|
ajinidev/MyLearning
|
30a7f20a57351ababaa9c0cc24dbbefd63c9d687
|
f17532915d4d7cdc2da5f175b6d18393c39c46bf
|
refs/heads/master
| 2023-07-04T01:47:05.093061
| 2021-08-16T17:05:41
| 2021-08-16T17:05:41
| 361,156,321
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,653
|
cpp
|
002 - HamiltonianCycle.cpp
|
#include "pch.h"
#include <string>
#include <vector>
using namespace std;
class HamiltonianCycle {
int numVertex;
int* path;
vector<vector<int>> matrix;
HamiltonianCycle(vector<vector<int>> matrix) : matrix(matrix) {
numVertex = matrix.size();
path = new int[numVertex];
}
vector<int> getHamiltonianPath() {
path[0] = 0;
if (findFeasibleSolution(1)) {
printHamiltonianPath();
}
}
bool findFeasibleSolution(int position) {
if (position == numVertex) {
if (matrix[path[position - 1]][path[0]] == 1) {
return true;
}
return false;
}
for (int idx = 1; idx < numVertex; idx++) {
if (isFeasible(idx, position)) {
path[position] = idx;
if (findFeasibleSolution(position + 1)) {
return true;
}
path[position] = 0;
}
}
return false;
}
bool isFeasible(int vertIdx, int position) {
// Check whether the nodes are connected or not.
if (matrix[path[vertIdx - 1]][vertIdx] == 0) {
return false;
}
// check whether the node is visited or not. if visited, then return false
for (int i = 0; i < position; i++) {
if (path[i] == vertIdx) {
return false;
}
}
return true;
}
vector<int> printHamiltonianPath() {
vector<int> vec;
for (int i = 0; i < numVertex; i++) {
vec.push_back(path[i]);
}
return vec;
}
};
|
cb7a1a80dbc53e82a66c2da8c81514e115e21379
|
9364532f28b197228b6e0188d863aca0222d6795
|
/src/cpp/H8R.cpp
|
1fb0e4ed420d67d546abb111804e8b082430a269
|
[] |
no_license
|
haoxiangmiao/finite_elements_assignment
|
c1782b91ab1949bbb71eeb1d1c90b0109eaa2748
|
07d18600fa572ca209948d7b607994217336028a
|
refs/heads/master
| 2021-05-17T18:22:45.126574
| 2019-06-19T11:02:49
| 2019-06-19T11:02:49
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 49,752
|
cpp
|
H8R.cpp
|
/*****************************************************************************/
/* STAP++ : A C++ FEM code sharing the same input data file with STAP90 */
/* Computational Dynamics Laboratory */
/* School of Aerospace Engineering, Tsinghua University */
/* */
/* Release 1.11, November 22, 2017 */
/* */
/* http://www.comdyn.cn/ */
/*****************************************************************************/
#include "H8R.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// Constructor
CH8R::CH8R()
{
NEN_ = 8; // Each element has 8 nodes
nodes_ = new CNode*[NEN_];
ND_ = 24;
LocationMatrix_ = new unsigned int[ND_];
ElementMaterial_ = nullptr;
}
// Desconstructor
CH8R::~CH8R()
{
}
// Read element data from stream Input
bool CH8R::Read(ifstream& Input, unsigned int Ele, CMaterial* MaterialSets, CNode* NodeList)
{
unsigned int N;
Input >> N; // element number
if (N != Ele + 1)
{
cerr << "*** Error *** Elements must be inputted in order !" << endl
<< " Expected element : " << Ele + 1 << endl
<< " Provided element : " << N << endl;
return false;
}
unsigned int MSet; // Material property set number
unsigned int N1, N2, N3, N4, N5, N6, N7, N8 ; // four node numbers
Input >> N1 >> N2 >> N3 >> N4>> N5 >> N6 >> N7 >> N8 >> MSet;
ElementMaterial_ = dynamic_cast<CH8Material*>(MaterialSets) + MSet - 1;
nodes_[0] = &NodeList[N1 - 1];
nodes_[1] = &NodeList[N2 - 1];
nodes_[2] = &NodeList[N3 - 1];
nodes_[3] = &NodeList[N4 - 1];
nodes_[4] = &NodeList[N5 - 1];
nodes_[5] = &NodeList[N6 - 1];
nodes_[6] = &NodeList[N7 - 1];
nodes_[7] = &NodeList[N8 - 1];
return true;
}
// Write element data to stream
void CH8R::Write(COutputter& output, unsigned int Ele)
{
output << setw(5) << Ele+1 << setw(11) << nodes_[0]->NodeNumber
<< setw(9) << nodes_[1]->NodeNumber << setw(9) << nodes_[2]->NodeNumber
<< setw(9) << nodes_[3]->NodeNumber << setw(9) << nodes_[4]->NodeNumber <<
setw(9) << nodes_[5]->NodeNumber << setw(9) << nodes_[6]->NodeNumber <<
setw(9) << nodes_[7]->NodeNumber << setw(12) << ElementMaterial_->nset << endl;
}
void CH8R::WritePlot(COutPlot& output, unsigned int Ele)
{
output << 8 << setw(11) << nodes_[0]->NodeNumber-1 << setw(9) << nodes_[1]->NodeNumber-1 << setw(9) << nodes_[3]->NodeNumber-1
<< setw(9) << nodes_[2]->NodeNumber-1 << setw(9) << nodes_[4]->NodeNumber-1 <<
setw(9) << nodes_[5]->NodeNumber-1 << setw(9) << nodes_[7]->NodeNumber-1 <<
setw(9) << nodes_[6]->NodeNumber-1 << endl;
}
void CH8R::WritePlotPost(COutPlotPost& output, unsigned int Ele)
{
output << 8 << setw(11) << nodes_[0]->NodeNumber-1 << setw(9) << nodes_[1]->NodeNumber-1 << setw(9) << nodes_[3]->NodeNumber-1
<< setw(9) << nodes_[2]->NodeNumber-1 << setw(9) << nodes_[4]->NodeNumber-1 <<
setw(9) << nodes_[5]->NodeNumber-1 << setw(9) << nodes_[7]->NodeNumber-1 <<
setw(9) << nodes_[6]->NodeNumber-1 << endl;
}
// Generate location matrix: the global equation number that corresponding to each DOF of the element
// Caution: Equation number is numbered from 1 !
void CH8R::GenerateLocationMatrix()
{
unsigned int i = 0;
for (unsigned int N = 0; N < NEN_; N++)
for (unsigned int D = 0; D < 3; D++)
LocationMatrix_[i++] = nodes_[N]->bcode[D];
/* printf("LM\n");
for (int ii=0;ii<8;ii++)
printf("%d\n",LocationMatrix_[ii]);
*/
}
// Return the size of the element stiffness matrix (stored as an array column by column)
// For 8H element, element stiffness is a 24x24 matrix, whose upper triangular part
// has 300 elements
unsigned int CH8R::SizeOfStiffnessMatrix() { return 300; }
// Calculate element stiffness matrix
// Upper triangular matrix, stored as an array column by colum starting from the diagonal element
void CH8R::CalculateBe (double* Be, double psi, double eta, double zet)
{
//GN matrix
double GN[12];
GN[0] = (1-eta)*(1-zet)/8;
GN[1] = (1-eta)*(1+zet)/8;
GN[2] = (1+eta)*(1-zet)/8;
GN[3] = (1+eta)*(1+zet)/8;
GN[4] = (1-psi)*(1-zet)/8;
GN[5] = (1-psi)*(1+zet)/8;
GN[6] = (1+psi)*(1-zet)/8;
GN[7] = (1+psi)*(1+zet)/8;
GN[8] = (1-eta)*(1-psi)/8;
GN[9] = (1-eta)*(1+psi)/8;
GN[10] = (1+eta)*(1-psi)/8;
GN[11] = (1+eta)*(1+psi)/8;
//Jaccobi
// [0 3 6]
// [1 4 7]
// [2 5 8]
double Ja[9];
Ja[0] = -GN[0]*nodes_[0]->XYZ[0] +GN[0]*nodes_[1]->XYZ[0] +GN[2]*nodes_[2]->XYZ[0] -GN[2]*nodes_[3]->XYZ[0]
-GN[1]*nodes_[4]->XYZ[0] +GN[1]*nodes_[5]->XYZ[0] +GN[3]*nodes_[6]->XYZ[0] -GN[3]*nodes_[7]->XYZ[0];
Ja[1] = -GN[4]*nodes_[0]->XYZ[0] -GN[6]*nodes_[1]->XYZ[0] +GN[6]*nodes_[2]->XYZ[0] +GN[4]*nodes_[3]->XYZ[0]
-GN[5]*nodes_[4]->XYZ[0] -GN[7]*nodes_[5]->XYZ[0] +GN[7]*nodes_[6]->XYZ[0] +GN[5]*nodes_[7]->XYZ[0];
Ja[2] = -GN[8]*nodes_[0]->XYZ[0] -GN[9]*nodes_[1]->XYZ[0] -GN[11]*nodes_[2]->XYZ[0] -GN[10]*nodes_[3]->XYZ[0]
+GN[8]*nodes_[4]->XYZ[0] +GN[9]*nodes_[5]->XYZ[0] +GN[11]*nodes_[6]->XYZ[0] +GN[10]*nodes_[7]->XYZ[0];
Ja[3] = -GN[0]*nodes_[0]->XYZ[1] +GN[0]*nodes_[1]->XYZ[1] +GN[2]*nodes_[2]->XYZ[1] -GN[2]*nodes_[3]->XYZ[1]
-GN[1]*nodes_[4]->XYZ[1] +GN[1]*nodes_[5]->XYZ[1] +GN[3]*nodes_[6]->XYZ[1] -GN[3]*nodes_[7]->XYZ[1];
Ja[4] = -GN[4]*nodes_[0]->XYZ[1] -GN[6]*nodes_[1]->XYZ[1] +GN[6]*nodes_[2]->XYZ[1] +GN[4]*nodes_[3]->XYZ[1]
-GN[5]*nodes_[4]->XYZ[1] -GN[7]*nodes_[5]->XYZ[1] +GN[7]*nodes_[6]->XYZ[1] +GN[5]*nodes_[7]->XYZ[1];
Ja[5] = -GN[8]*nodes_[0]->XYZ[1] -GN[9]*nodes_[1]->XYZ[1] -GN[11]*nodes_[2]->XYZ[1] -GN[10]*nodes_[3]->XYZ[1]
+GN[8]*nodes_[4]->XYZ[1] +GN[9]*nodes_[5]->XYZ[1] +GN[11]*nodes_[6]->XYZ[1] +GN[10]*nodes_[7]->XYZ[1];
Ja[6] = -GN[0]*nodes_[0]->XYZ[2] +GN[0]*nodes_[1]->XYZ[2] +GN[2]*nodes_[2]->XYZ[2] -GN[2]*nodes_[3]->XYZ[2]
-GN[1]*nodes_[4]->XYZ[2] +GN[1]*nodes_[5]->XYZ[2] +GN[3]*nodes_[6]->XYZ[2] -GN[3]*nodes_[7]->XYZ[2];
Ja[7] = -GN[4]*nodes_[0]->XYZ[2] -GN[6]*nodes_[1]->XYZ[2] +GN[6]*nodes_[2]->XYZ[2] +GN[4]*nodes_[3]->XYZ[2]
-GN[5]*nodes_[4]->XYZ[2] -GN[7]*nodes_[5]->XYZ[2] +GN[7]*nodes_[6]->XYZ[2] +GN[5]*nodes_[7]->XYZ[2];
Ja[8] = -GN[8]*nodes_[0]->XYZ[2] -GN[9]*nodes_[1]->XYZ[2] -GN[11]*nodes_[2]->XYZ[2] -GN[10]*nodes_[3]->XYZ[2]
+GN[8]*nodes_[4]->XYZ[2] +GN[9]*nodes_[5]->XYZ[2] +GN[11]*nodes_[6]->XYZ[2] +GN[10]*nodes_[7]->XYZ[2];
// printf("jac: \n");
// for (int i=0;i<9;i++)
// printf("%lf\n",Ja[i]);
// printf("\n");
double JaCof[9];
JaCof[0] = Ja[4]*Ja[8]-Ja[5]*Ja[7];
JaCof[1] = -Ja[3]*Ja[8]+Ja[5]*Ja[6];
JaCof[2] = Ja[3]*Ja[7]-Ja[4]*Ja[6];
JaCof[3] = -Ja[1]*Ja[8]+Ja[2]*Ja[7];
JaCof[4] = Ja[0]*Ja[8]-Ja[2]*Ja[6];
JaCof[5] = -Ja[0]*Ja[7]+Ja[1]*Ja[6];
JaCof[6] = Ja[1]*Ja[5]-Ja[2]*Ja[4];
JaCof[7] = -Ja[0]*Ja[5]+Ja[2]*Ja[3];
JaCof[8] = Ja[0]*Ja[4]-Ja[1]*Ja[3];
double JaDet;
JaDet = Ja[0]*JaCof[0] + Ja[1]*JaCof[1] + Ja[2]*JaCof[2];
// printf("jacdet: %lf\n\n",JaDet);
//inversion
double JaInv[9];
JaInv[0] = JaCof[0]/JaDet;
JaInv[1] = JaCof[3]/JaDet;
JaInv[2] = JaCof[6]/JaDet;
JaInv[3] = JaCof[1]/JaDet;
JaInv[4] = JaCof[4]/JaDet;
JaInv[5] = JaCof[7]/JaDet;
JaInv[6] = JaCof[2]/JaDet;
JaInv[7] = JaCof[5]/JaDet;
JaInv[8] = JaCof[8]/JaDet;
//Be [1x 1y 1z ... 8z JaDet] 25 menbers
Be[0] = -JaInv[0]*GN[0] -JaInv[3]*GN[4] -JaInv[6]*GN[8];
Be[3] = JaInv[0]*GN[0] -JaInv[3]*GN[6] -JaInv[6]*GN[9];
Be[6] = JaInv[0]*GN[2] +JaInv[3]*GN[6] -JaInv[6]*GN[11];
Be[9] = -JaInv[0]*GN[2] +JaInv[3]*GN[4] -JaInv[6]*GN[10];
Be[12] = -JaInv[0]*GN[1] -JaInv[3]*GN[5] +JaInv[6]*GN[8];
Be[15] = JaInv[0]*GN[1] -JaInv[3]*GN[7] +JaInv[6]*GN[9];
Be[18] = JaInv[0]*GN[3] +JaInv[3]*GN[7] +JaInv[6]*GN[11];
Be[21] = -JaInv[0]*GN[3] +JaInv[3]*GN[5] +JaInv[6]*GN[10];
Be[1] = -JaInv[1]*GN[0] -JaInv[4]*GN[4] -JaInv[7]*GN[8];
Be[4] = JaInv[1]*GN[0] -JaInv[4]*GN[6] -JaInv[7]*GN[9];
Be[7] = JaInv[1]*GN[2] +JaInv[4]*GN[6] -JaInv[7]*GN[11];
Be[10] = -JaInv[1]*GN[2] +JaInv[4]*GN[4] -JaInv[7]*GN[10];
Be[13] = -JaInv[1]*GN[1] -JaInv[4]*GN[5] +JaInv[7]*GN[8];
Be[16] = JaInv[1]*GN[1] -JaInv[4]*GN[7] +JaInv[7]*GN[9];
Be[19] = JaInv[1]*GN[3] +JaInv[4]*GN[7] +JaInv[7]*GN[11];
Be[22] = -JaInv[1]*GN[3] +JaInv[4]*GN[5] +JaInv[7]*GN[10];
Be[2] = -JaInv[2]*GN[0] -JaInv[5]*GN[4] -JaInv[8]*GN[8];
Be[5] = JaInv[2]*GN[0] -JaInv[5]*GN[6] -JaInv[8]*GN[9];
Be[8] = JaInv[2]*GN[2] +JaInv[5]*GN[6] -JaInv[8]*GN[11];
Be[11] = -JaInv[2]*GN[2] +JaInv[5]*GN[4] -JaInv[8]*GN[10];
Be[14] = -JaInv[2]*GN[1] -JaInv[5]*GN[5] +JaInv[8]*GN[8];
Be[17] = JaInv[2]*GN[1] -JaInv[5]*GN[7] +JaInv[8]*GN[9];
Be[20] = JaInv[2]*GN[3] +JaInv[5]*GN[7] +JaInv[8]*GN[11];
Be[23] = -JaInv[2]*GN[3] +JaInv[5]*GN[5] +JaInv[8]*GN[10];
Be[24] = JaDet;
/*
printf("Be\n");
for (int i=0;i<24;i++)
printf("%lf\n",Be[i]);
printf("\n");
*/
}
void CH8R::ElementStiffness(double* Matrix)
{
clear(Matrix, SizeOfStiffnessMatrix());
double Be[25];
CalculateBe(Be,0,0,0);
CalculateMatrix(Be, Matrix);
for (unsigned int i=0;i<SizeOfStiffnessMatrix();i++)
Matrix[i] = Matrix[i]*8;
}
// Calculate element stress
void CH8R::ElementStress(double* stress, double* Displacement)
{
double Be[25];
CalculateBe(Be,0,0,0);
CalculateStress(Be, stress, Displacement);
}
void CH8R::ElementCoord (double* coord)
{
CalculateCoord (coord, 0, 0, 0);
}
void CH8R::CalculateCoord (double* coord, double psi, double eta, double zet)
{
double N[8];
N[0] = (1-psi)*(1-eta)*(1-zet)/8;
N[1] = (1+psi)*(1-eta)*(1-zet)/8;
N[2] = (1+psi)*(1+eta)*(1-zet)/8;
N[3] = (1-psi)*(1+eta)*(1-zet)/8;
N[4] = (1-psi)*(1-eta)*(1+zet)/8;
N[5] = (1+psi)*(1-eta)*(1+zet)/8;
N[6] = (1+psi)*(1+eta)*(1+zet)/8;
N[7] = (1-psi)*(1+eta)*(1+zet)/8;
coord[0] = nodes_[0]->XYZ[0]*N[0] +nodes_[1]->XYZ[0]*N[1] +nodes_[2]->XYZ[0]*N[2] +nodes_[3]->XYZ[0]*N[3] +nodes_[4]->XYZ[0]*N[4] +nodes_[5]->XYZ[0]*N[5] +nodes_[6]->XYZ[0]*N[6] +nodes_[7]->XYZ[0]*N[7];
coord[1] = nodes_[0]->XYZ[1]*N[0] +nodes_[1]->XYZ[1]*N[1] +nodes_[2]->XYZ[1]*N[2] +nodes_[3]->XYZ[1]*N[3] +nodes_[4]->XYZ[1]*N[4] +nodes_[5]->XYZ[1]*N[5] +nodes_[6]->XYZ[1]*N[6] +nodes_[7]->XYZ[1]*N[7];
coord[2] = nodes_[0]->XYZ[2]*N[0] +nodes_[1]->XYZ[2]*N[1] +nodes_[2]->XYZ[2]*N[2] +nodes_[3]->XYZ[2]*N[3] +nodes_[4]->XYZ[2]*N[4] +nodes_[5]->XYZ[2]*N[5] +nodes_[6]->XYZ[2]*N[6] +nodes_[7]->XYZ[2]*N[7];
}
void CH8R::CalculateStress (double* Be, double* stress, double* Displacement)
{
CH8Material* material_ = dynamic_cast<CH8Material*>(ElementMaterial_);
double CM[3];
CM[1]= material_->Lam;
CM[2]= material_->G;
CM[0]= 2*CM[2] + CM[1];
double strain[6];
for (int i=0;i<8;i++)
{
if (LocationMatrix_[3*i])
{
strain[0] = strain[0] + Be[3*i]*Displacement[LocationMatrix_[3*i]-1];
strain[4] = strain[4] + Be[3*i+2]*Displacement[LocationMatrix_[3*i]-1];
strain[5] = strain[5] + Be[3*i+1]*Displacement[LocationMatrix_[3*i]-1];
}
if (LocationMatrix_[3*i+1])
{
strain[1] = strain[1] + Be[3*i+1]*Displacement[LocationMatrix_[3*i+1]-1];
strain[3] = strain[3] + Be[3*i+2]*Displacement[LocationMatrix_[3*i+1]-1];
strain[5] = strain[5] + Be[3*i]*Displacement[LocationMatrix_[3*i+1]-1];
}
if (LocationMatrix_[3*i+2])
{
strain[2] = strain[2] + Be[3*i+2]*Displacement[LocationMatrix_[3*i+2]-1];
strain[3] = strain[3] + Be[3*i+1]*Displacement[LocationMatrix_[3*i+2]-1];
strain[4] = strain[4] + Be[3*i]*Displacement[LocationMatrix_[3*i+2]-1];
}
}
/*
strain[0] = Be[0]*Displacement[LocationMatrix_[0]-1]*(double)(!LocationMatrix_[0]==0) +Be[3]*Displacement[LocationMatrix_[3]-1]*(double)(!LocationMatrix_[3]==0) +Be[6]*Displacement[LocationMatrix_[6]-1]*(double)(!LocationMatrix_[6]==0) +Be[9]*Displacement[LocationMatrix_[9]-1]*(double)(!LocationMatrix_[9]==0) +Be[12]*Displacement[LocationMatrix_[12]-1]*(double)(!LocationMatrix_[12]==0) +Be[15]*Displacement[LocationMatrix_[15]-1]*(double)(!LocationMatrix_[15]==0) +Be[18]*Displacement[LocationMatrix_[18]-1]*(double)(!LocationMatrix_[18]==0) +Be[21]*Displacement[LocationMatrix_[21]-1]*(double)(!LocationMatrix_[21]==0);
strain[1] = Be[1]*Displacement[LocationMatrix_[1]-1]*(double)(!LocationMatrix_[1]==0) +Be[4]*Displacement[LocationMatrix_[4]-1]*(double)(!LocationMatrix_[4]==0) +Be[7]*Displacement[LocationMatrix_[7]-1]*(double)(!LocationMatrix_[7]==0) +Be[10]*Displacement[LocationMatrix_[10]-1]*(double)(!LocationMatrix_[10]==0) +Be[13]*Displacement[LocationMatrix_[13]-1]*(double)(!LocationMatrix_[13]==0) +Be[16]*Displacement[LocationMatrix_[16]-1]*(double)(!LocationMatrix_[16]==0) +Be[19]*Displacement[LocationMatrix_[19]-1]*(double)(!LocationMatrix_[19]==0) +Be[22]*Displacement[LocationMatrix_[22]-1]*(double)(!LocationMatrix_[22]==0);
strain[2] = Be[2]*Displacement[LocationMatrix_[2]-1]*(double)(!LocationMatrix_[2]==0) +Be[5]*Displacement[LocationMatrix_[5]-1]*(double)(!LocationMatrix_[5]==0) +Be[8]*Displacement[LocationMatrix_[8]-1]*(double)(!LocationMatrix_[8]==0) +Be[11]*Displacement[LocationMatrix_[11]-1]*(double)(!LocationMatrix_[11]==0) +Be[14]*Displacement[LocationMatrix_[14]-1]*(double)(!LocationMatrix_[14]==0) +Be[17]*Displacement[LocationMatrix_[17]-1]*(double)(!LocationMatrix_[17]==0) +Be[20]*Displacement[LocationMatrix_[20]-1]*(double)(!LocationMatrix_[20]==0) +Be[23]*Displacement[LocationMatrix_[23]-1]*(double)(!LocationMatrix_[23]==0);
strain[3] = Be[2]*Displacement[LocationMatrix_[1]-1]*(double)(!LocationMatrix_[1]==0) +Be[1]*Displacement[LocationMatrix_[2]-1]*(double)(!LocationMatrix_[2]==0) +Be[5]*Displacement[LocationMatrix_[4]-1]*(double)(!LocationMatrix_[4]==0) +Be[4]*Displacement[LocationMatrix_[5]-1]*(double)(!LocationMatrix_[5]==0) +Be[8]*Displacement[LocationMatrix_[7]-1]*(double)(!LocationMatrix_[7]==0) +Be[7]*Displacement[LocationMatrix_[8]-1]*(double)(!LocationMatrix_[8]==0) +Be[11]*Displacement[LocationMatrix_[10]-1]*(double)(!LocationMatrix_[10]==0) +Be[10]*Displacement[LocationMatrix_[11]-1]*(double)(!LocationMatrix_[11]==0) +Be[14]*Displacement[LocationMatrix_[13]-1]*(double)(!LocationMatrix_[13]==0) +Be[13]*Displacement[LocationMatrix_[14]-1]*(double)(!LocationMatrix_[14]==0) +Be[17]*Displacement[LocationMatrix_[16]-1]*(double)(!LocationMatrix_[16]==0) +Be[16]*Displacement[LocationMatrix_[17]-1]*(double)(!LocationMatrix_[17]==0) +Be[20]*Displacement[LocationMatrix_[19]-1]*(double)(!LocationMatrix_[19]==0) +Be[19]*Displacement[LocationMatrix_[20]-1]*(double)(!LocationMatrix_[20]==0) +Be[23]*Displacement[LocationMatrix_[22]-1]*(double)(!LocationMatrix_[22]==0) +Be[22]*Displacement[LocationMatrix_[23]-1]*(double)(!LocationMatrix_[23]==0);
strain[4] = Be[2]*Displacement[LocationMatrix_[0]-1]*(double)(!LocationMatrix_[0]==0) +Be[0]*Displacement[LocationMatrix_[2]-1]*(double)(!LocationMatrix_[2]==0) +Be[5]*Displacement[LocationMatrix_[3]-1]*(double)(!LocationMatrix_[3]==0) +Be[3]*Displacement[LocationMatrix_[5]-1]*(double)(!LocationMatrix_[5]==0) +Be[8]*Displacement[LocationMatrix_[6]-1]*(double)(!LocationMatrix_[6]==0) +Be[6]*Displacement[LocationMatrix_[8]-1]*(double)(!LocationMatrix_[8]==0) +Be[11]*Displacement[LocationMatrix_[9]-1]*(double)(!LocationMatrix_[9]==0) +Be[9]*Displacement[LocationMatrix_[11]-1]*(double)(!LocationMatrix_[11]==0) +Be[14]*Displacement[LocationMatrix_[12]-1]*(double)(!LocationMatrix_[12]==0) +Be[12]*Displacement[LocationMatrix_[14]-1]*(double)(!LocationMatrix_[14]==0) +Be[17]*Displacement[LocationMatrix_[15]-1]*(double)(!LocationMatrix_[15]==0) +Be[15]*Displacement[LocationMatrix_[17]-1]*(double)(!LocationMatrix_[17]==0) +Be[20]*Displacement[LocationMatrix_[18]-1]*(double)(!LocationMatrix_[18]==0) +Be[18]*Displacement[LocationMatrix_[20]-1]*(double)(!LocationMatrix_[20]==0) +Be[23]*Displacement[LocationMatrix_[21]-1]*(double)(!LocationMatrix_[21]==0) +Be[21]*Displacement[LocationMatrix_[23]-1]*(double)(!LocationMatrix_[23]==0);
strain[5] = Be[1]*Displacement[LocationMatrix_[0]-1]*(double)(!LocationMatrix_[0]==0) +Be[0]*Displacement[LocationMatrix_[1]-1]*(double)(!LocationMatrix_[1]==0) +Be[4]*Displacement[LocationMatrix_[3]-1]*(double)(!LocationMatrix_[3]==0) +Be[3]*Displacement[LocationMatrix_[4]-1]*(double)(!LocationMatrix_[4]==0) +Be[7]*Displacement[LocationMatrix_[6]-1]*(double)(!LocationMatrix_[6]==0) +Be[6]*Displacement[LocationMatrix_[7]-1]*(double)(!LocationMatrix_[7]==0) +Be[10]*Displacement[LocationMatrix_[9]-1]*(double)(!LocationMatrix_[9]==0) +Be[9]*Displacement[LocationMatrix_[10]-1]*(double)(!LocationMatrix_[10]==0) +Be[13]*Displacement[LocationMatrix_[12]-1]*(double)(!LocationMatrix_[12]==0) +Be[12]*Displacement[LocationMatrix_[13]-1]*(double)(!LocationMatrix_[13]==0) +Be[16]*Displacement[LocationMatrix_[15]-1]*(double)(!LocationMatrix_[15]==0) +Be[15]*Displacement[LocationMatrix_[16]-1]*(double)(!LocationMatrix_[16]==0) +Be[19]*Displacement[LocationMatrix_[18]-1]*(double)(!LocationMatrix_[18]==0) +Be[18]*Displacement[LocationMatrix_[19]-1]*(double)(!LocationMatrix_[19]==0) +Be[22]*Displacement[LocationMatrix_[21]-1]*(double)(!LocationMatrix_[21]==0) +Be[21]*Displacement[LocationMatrix_[22]-1]*(double)(!LocationMatrix_[22]==0);
*/
stress[0] = CM[0]*strain[0] +CM[1]*strain[1] +CM[1]*strain[2];
stress[1] = CM[1]*strain[0] +CM[0]*strain[1] +CM[1]*strain[2];
stress[2] = CM[1]*strain[0] +CM[1]*strain[1] +CM[0]*strain[2];
stress[3] = CM[2]*strain[3];
stress[4] = CM[2]*strain[4];
stress[5] = CM[2]*strain[5];
}
void CH8R::CalculateVolume (double* EG, double psi, double eta, double zet)
{
//GN matrix
double GN[12];
GN[0] = (1-eta)*(1-zet)/8;
GN[1] = (1-eta)*(1+zet)/8;
GN[2] = (1+eta)*(1-zet)/8;
GN[3] = (1+eta)*(1+zet)/8;
GN[4] = (1-psi)*(1-zet)/8;
GN[5] = (1-psi)*(1+zet)/8;
GN[6] = (1+psi)*(1-zet)/8;
GN[7] = (1+psi)*(1+zet)/8;
GN[8] = (1-eta)*(1-psi)/8;
GN[9] = (1-eta)*(1+psi)/8;
GN[10] = (1+eta)*(1-psi)/8;
GN[11] = (1+eta)*(1+psi)/8;
//Jaccobi
// [0 3 6]
// [1 4 7]
// [2 5 8]
double Ja[9];
Ja[0] = -GN[0]*nodes_[0]->XYZ[0] +GN[0]*nodes_[1]->XYZ[0] +GN[2]*nodes_[2]->XYZ[0] -GN[2]*nodes_[3]->XYZ[0]
-GN[1]*nodes_[4]->XYZ[0] +GN[1]*nodes_[5]->XYZ[0] +GN[3]*nodes_[6]->XYZ[0] -GN[3]*nodes_[7]->XYZ[0];
Ja[1] = -GN[4]*nodes_[0]->XYZ[0] -GN[6]*nodes_[1]->XYZ[0] +GN[6]*nodes_[2]->XYZ[0] +GN[4]*nodes_[3]->XYZ[0]
-GN[5]*nodes_[4]->XYZ[0] -GN[7]*nodes_[5]->XYZ[0] +GN[7]*nodes_[6]->XYZ[0] +GN[5]*nodes_[7]->XYZ[0];
Ja[2] = -GN[8]*nodes_[0]->XYZ[0] -GN[9]*nodes_[1]->XYZ[0] -GN[11]*nodes_[2]->XYZ[0] -GN[10]*nodes_[3]->XYZ[0]
+GN[8]*nodes_[4]->XYZ[0] +GN[9]*nodes_[5]->XYZ[0] +GN[11]*nodes_[6]->XYZ[0] +GN[10]*nodes_[7]->XYZ[0];
Ja[3] = -GN[0]*nodes_[0]->XYZ[1] +GN[0]*nodes_[1]->XYZ[1] +GN[2]*nodes_[2]->XYZ[1] -GN[2]*nodes_[3]->XYZ[1]
-GN[1]*nodes_[4]->XYZ[1] +GN[1]*nodes_[5]->XYZ[1] +GN[3]*nodes_[6]->XYZ[1] -GN[3]*nodes_[7]->XYZ[1];
Ja[4] = -GN[4]*nodes_[0]->XYZ[1] -GN[6]*nodes_[1]->XYZ[1] +GN[6]*nodes_[2]->XYZ[1] +GN[4]*nodes_[3]->XYZ[1]
-GN[5]*nodes_[4]->XYZ[1] -GN[7]*nodes_[5]->XYZ[1] +GN[7]*nodes_[6]->XYZ[1] +GN[5]*nodes_[7]->XYZ[1];
Ja[5] = -GN[8]*nodes_[0]->XYZ[1] -GN[9]*nodes_[1]->XYZ[1] -GN[11]*nodes_[2]->XYZ[1] -GN[10]*nodes_[3]->XYZ[1]
+GN[8]*nodes_[4]->XYZ[1] +GN[9]*nodes_[5]->XYZ[1] +GN[11]*nodes_[6]->XYZ[1] +GN[10]*nodes_[7]->XYZ[1];
Ja[6] = -GN[2]*nodes_[0]->XYZ[2] +GN[2]*nodes_[1]->XYZ[2] +GN[2]*nodes_[2]->XYZ[2] -GN[2]*nodes_[3]->XYZ[2]
-GN[1]*nodes_[4]->XYZ[2] +GN[1]*nodes_[5]->XYZ[2] +GN[3]*nodes_[6]->XYZ[2] -GN[3]*nodes_[7]->XYZ[2];
Ja[7] = -GN[4]*nodes_[0]->XYZ[2] -GN[6]*nodes_[1]->XYZ[2] +GN[6]*nodes_[2]->XYZ[2] +GN[4]*nodes_[3]->XYZ[2]
-GN[5]*nodes_[4]->XYZ[2] -GN[7]*nodes_[5]->XYZ[2] +GN[7]*nodes_[6]->XYZ[2] +GN[5]*nodes_[7]->XYZ[2];
Ja[8] = -GN[8]*nodes_[0]->XYZ[2] -GN[9]*nodes_[1]->XYZ[2] -GN[11]*nodes_[2]->XYZ[2] -GN[10]*nodes_[3]->XYZ[2]
+GN[8]*nodes_[4]->XYZ[2] +GN[9]*nodes_[5]->XYZ[2] +GN[11]*nodes_[6]->XYZ[2] +GN[10]*nodes_[7]->XYZ[2];
double JaDet;
JaDet = Ja[0]*(Ja[4]*Ja[8]-Ja[5]*Ja[7]) + Ja[1]*(-Ja[3]*Ja[8]+Ja[5]*Ja[6]) + Ja[2]*(Ja[3]*Ja[7]-Ja[4]*Ja[6]);
double N[8];
N[0] = (1-psi)*(1-eta)*(1-zet)/8;
N[1] = (1+psi)*(1-eta)*(1-zet)/8;
N[2] = (1+psi)*(1+eta)*(1-zet)/8;
N[3] = (1-psi)*(1+eta)*(1-zet)/8;
N[4] = (1-psi)*(1-eta)*(1+zet)/8;
N[5] = (1+psi)*(1-eta)*(1+zet)/8;
N[6] = (1+psi)*(1+eta)*(1+zet)/8;
N[7] = (1-psi)*(1+eta)*(1+zet)/8;
for (unsigned int i=0;i<NEN_;i++)
EG[i] = EG[i] + N[i]*JaDet;
}
void CH8R::GravityCalculation (double* EG)
{
clear(EG, NEN_);
double Ga=0.57735;
CalculateVolume(EG, -Ga, -Ga, -Ga);
CalculateVolume(EG, Ga, -Ga, -Ga);
CalculateVolume(EG, Ga, Ga, -Ga);
CalculateVolume(EG, -Ga, Ga, -Ga);
CalculateVolume(EG, -Ga, -Ga, Ga);
CalculateVolume(EG, Ga, -Ga, Ga);
CalculateVolume(EG, Ga, Ga, Ga);
CalculateVolume(EG, -Ga, Ga, Ga);
CH8Material* material_ = dynamic_cast<CH8Material*>(ElementMaterial_);
for (unsigned int i=0;i<NEN_;i++)
// EG[i]= 0;
EG[i]= EG[i]*material_->Rou*9.8;
}
/*
void CH8R::ElementPostInfo(double* stress, double* Displacement, double* PrePositions, double* PostPositions)
{
for (unsigned int i=0;i<NEN_;i++)
{
for (unsigned int j=0;j<3;j++)
{
PrePositions[3*i+j] = nodes_[i] ->XYZ[0];
if (LocationMatrix_[3*i+j])
PostPositions[3*i+j] = PrePositions[3*i+j] + Displacement[LocationMatrix_[3*i+j]-1];
else
PostPositions[3*i+j] = PrePositions[3*i+j];
}
}
ElementStress(stress, Displacement);
}
*/
void CH8R::CalculateMatrix (double* Be, double* Matrix)
{
CH8Material* material_ = dynamic_cast<CH8Material*>(ElementMaterial_);
double CM[3];
CM[1]= material_->Lam;
CM[2]= material_->G;
CM[0]= 2*CM[2] + CM[1];
Matrix[ 0] = Matrix[0] + ( Be[0]*CM[0]* Be[0] + Be[1]*CM[2]* Be[1] + Be[2]*CM[2]* Be[2] )*Be[24];
Matrix[ 1] = Matrix[1] + ( Be[0]*CM[2]* Be[0] + Be[1]*CM[0]* Be[1] + Be[2]*CM[2]* Be[2] )*Be[24];
Matrix[ 2] = Matrix[2] + ( Be[1]*CM[1]* Be[0] + Be[0]*CM[2]* Be[1] )*Be[24];
Matrix[ 3] = Matrix[3] + ( Be[0]*CM[2]* Be[0] + Be[1]*CM[2]* Be[1] + Be[2]*CM[0]* Be[2] )*Be[24];
Matrix[ 4] = Matrix[4] + ( Be[2]*CM[1]* Be[1] + Be[1]*CM[2]* Be[2] )*Be[24];
Matrix[ 5] = Matrix[5] + ( Be[2]*CM[1]* Be[0] + Be[0]*CM[2]* Be[2] )*Be[24];
Matrix[ 6] = Matrix[6] + ( Be[3]*CM[0]* Be[3] + Be[4]*CM[2]* Be[4] + Be[5]*CM[2]* Be[5] )*Be[24];
Matrix[ 7] = Matrix[7] + ( Be[3]*CM[1]* Be[2] + Be[5]*CM[2]* Be[0] )*Be[24];
Matrix[ 8] = Matrix[8] + ( Be[3]*CM[1]* Be[1] + Be[4]*CM[2]* Be[0] )*Be[24];
Matrix[ 9] = Matrix[9] + ( Be[3]*CM[0]* Be[0] + Be[4]*CM[2]* Be[1] + Be[5]*CM[2]* Be[2] )*Be[24];
Matrix[ 10] = Matrix[10] + ( Be[3]*CM[2]* Be[3] + Be[4]*CM[0]* Be[4] + Be[5]*CM[2]* Be[5] )*Be[24];
Matrix[ 11] = Matrix[11] + ( Be[4]*CM[1]* Be[3] + Be[3]*CM[2]* Be[4] )*Be[24];
Matrix[ 12] = Matrix[12] + ( Be[4]*CM[1]* Be[2] + Be[5]*CM[2]* Be[1] )*Be[24];
Matrix[ 13] = Matrix[13] + ( Be[3]*CM[2]* Be[0] + Be[4]*CM[0]* Be[1] + Be[5]*CM[2]* Be[2] )*Be[24];
Matrix[ 14] = Matrix[14] + ( Be[4]*CM[1]* Be[0] + Be[3]*CM[2]* Be[1] )*Be[24];
Matrix[ 15] = Matrix[15] + ( Be[3]*CM[2]* Be[3] + Be[4]*CM[2]* Be[4] + Be[5]*CM[0]* Be[5] )*Be[24];
Matrix[ 16] = Matrix[16] + ( Be[5]*CM[1]* Be[4] + Be[4]*CM[2]* Be[5] )*Be[24];
Matrix[ 17] = Matrix[17] + ( Be[5]*CM[1]* Be[3] + Be[3]*CM[2]* Be[5] )*Be[24];
Matrix[ 18] = Matrix[18] + ( Be[3]*CM[2]* Be[0] + Be[4]*CM[2]* Be[1] + Be[5]*CM[0]* Be[2] )*Be[24];
Matrix[ 19] = Matrix[19] + ( Be[5]*CM[1]* Be[1] + Be[4]*CM[2]* Be[2] )*Be[24];
Matrix[ 20] = Matrix[20] + ( Be[5]*CM[1]* Be[0] + Be[3]*CM[2]* Be[2] )*Be[24];
Matrix[ 21] = Matrix[21] + ( Be[6]*CM[0]* Be[6] + Be[7]*CM[2]* Be[7] + Be[8]*CM[2]* Be[8] )*Be[24];
Matrix[ 22] = Matrix[22] + ( Be[6]*CM[1]* Be[5] + Be[8]*CM[2]* Be[3] )*Be[24];
Matrix[ 23] = Matrix[23] + ( Be[6]*CM[1]* Be[4] + Be[7]*CM[2]* Be[3] )*Be[24];
Matrix[ 24] = Matrix[24] + ( Be[6]*CM[0]* Be[3] + Be[7]*CM[2]* Be[4] + Be[8]*CM[2]* Be[5] )*Be[24];
Matrix[ 25] = Matrix[25] + ( Be[6]*CM[1]* Be[2] + Be[8]*CM[2]* Be[0] )*Be[24];
Matrix[ 26] = Matrix[26] + ( Be[6]*CM[1]* Be[1] + Be[7]*CM[2]* Be[0] )*Be[24];
Matrix[ 27] = Matrix[27] + ( Be[6]*CM[0]* Be[0] + Be[7]*CM[2]* Be[1] + Be[8]*CM[2]* Be[2] )*Be[24];
Matrix[ 28] = Matrix[28] + ( Be[6]*CM[2]* Be[6] + Be[7]*CM[0]* Be[7] + Be[8]*CM[2]* Be[8] )*Be[24];
Matrix[ 29] = Matrix[29] + ( Be[7]*CM[1]* Be[6] + Be[6]*CM[2]* Be[7] )*Be[24];
Matrix[ 30] = Matrix[30] + ( Be[7]*CM[1]* Be[5] + Be[8]*CM[2]* Be[4] )*Be[24];
Matrix[ 31] = Matrix[31] + ( Be[6]*CM[2]* Be[3] + Be[7]*CM[0]* Be[4] + Be[8]*CM[2]* Be[5] )*Be[24];
Matrix[ 32] = Matrix[32] + ( Be[7]*CM[1]* Be[3] + Be[6]*CM[2]* Be[4] )*Be[24];
Matrix[ 33] = Matrix[33] + ( Be[7]*CM[1]* Be[2] + Be[8]*CM[2]* Be[1] )*Be[24];
Matrix[ 34] = Matrix[34] + ( Be[6]*CM[2]* Be[0] + Be[7]*CM[0]* Be[1] + Be[8]*CM[2]* Be[2] )*Be[24];
Matrix[ 35] = Matrix[35] + ( Be[7]*CM[1]* Be[0] + Be[6]*CM[2]* Be[1] )*Be[24];
Matrix[ 36] = Matrix[36] + ( Be[6]*CM[2]* Be[6] + Be[7]*CM[2]* Be[7] + Be[8]*CM[0]* Be[8] )*Be[24];
Matrix[ 37] = Matrix[37] + ( Be[8]*CM[1]* Be[7] + Be[7]*CM[2]* Be[8] )*Be[24];
Matrix[ 38] = Matrix[38] + ( Be[8]*CM[1]* Be[6] + Be[6]*CM[2]* Be[8] )*Be[24];
Matrix[ 39] = Matrix[39] + ( Be[6]*CM[2]* Be[3] + Be[7]*CM[2]* Be[4] + Be[8]*CM[0]* Be[5] )*Be[24];
Matrix[ 40] = Matrix[40] + ( Be[8]*CM[1]* Be[4] + Be[7]*CM[2]* Be[5] )*Be[24];
Matrix[ 41] = Matrix[41] + ( Be[8]*CM[1]* Be[3] + Be[6]*CM[2]* Be[5] )*Be[24];
Matrix[ 42] = Matrix[42] + ( Be[6]*CM[2]* Be[0] + Be[7]*CM[2]* Be[1] + Be[8]*CM[0]* Be[2] )*Be[24];
Matrix[ 43] = Matrix[43] + ( Be[8]*CM[1]* Be[1] + Be[7]*CM[2]* Be[2] )*Be[24];
Matrix[ 44] = Matrix[44] + ( Be[8]*CM[1]* Be[0] + Be[6]*CM[2]* Be[2] )*Be[24];
Matrix[ 45] = Matrix[45] + ( Be[9]*CM[0]* Be[9] + Be[10]*CM[2]* Be[10] + Be[11]*CM[2]* Be[11] )*Be[24];
Matrix[ 46] = Matrix[46] + ( Be[9]*CM[1]* Be[8] + Be[11]*CM[2]* Be[6] )*Be[24];
Matrix[ 47] = Matrix[47] + ( Be[9]*CM[1]* Be[7] + Be[10]*CM[2]* Be[6] )*Be[24];
Matrix[ 48] = Matrix[48] + ( Be[9]*CM[0]* Be[6] + Be[10]*CM[2]* Be[7] + Be[11]*CM[2]* Be[8] )*Be[24];
Matrix[ 49] = Matrix[49] + ( Be[9]*CM[1]* Be[5] + Be[11]*CM[2]* Be[3] )*Be[24];
Matrix[ 50] = Matrix[50] + ( Be[9]*CM[1]* Be[4] + Be[10]*CM[2]* Be[3] )*Be[24];
Matrix[ 51] = Matrix[51] + ( Be[9]*CM[0]* Be[3] + Be[10]*CM[2]* Be[4] + Be[11]*CM[2]* Be[5] )*Be[24];
Matrix[ 52] = Matrix[52] + ( Be[9]*CM[1]* Be[2] + Be[11]*CM[2]* Be[0] )*Be[24];
Matrix[ 53] = Matrix[53] + ( Be[9]*CM[1]* Be[1] + Be[10]*CM[2]* Be[0] )*Be[24];
Matrix[ 54] = Matrix[54] + ( Be[9]*CM[0]* Be[0] + Be[10]*CM[2]* Be[1] + Be[11]*CM[2]* Be[2] )*Be[24];
Matrix[ 55] = Matrix[55] + ( Be[9]*CM[2]* Be[9] + Be[10]*CM[0]* Be[10] + Be[11]*CM[2]* Be[11] )*Be[24];
Matrix[ 56] = Matrix[56] + ( Be[10]*CM[1]* Be[9] + Be[9]*CM[2]* Be[10] )*Be[24];
Matrix[ 57] = Matrix[57] + ( Be[10]*CM[1]* Be[8] + Be[11]*CM[2]* Be[7] )*Be[24];
Matrix[ 58] = Matrix[58] + ( Be[9]*CM[2]* Be[6] + Be[10]*CM[0]* Be[7] + Be[11]*CM[2]* Be[8] )*Be[24];
Matrix[ 59] = Matrix[59] + ( Be[10]*CM[1]* Be[6] + Be[9]*CM[2]* Be[7] )*Be[24];
Matrix[ 60] = Matrix[60] + ( Be[10]*CM[1]* Be[5] + Be[11]*CM[2]* Be[4] )*Be[24];
Matrix[ 61] = Matrix[61] + ( Be[9]*CM[2]* Be[3] + Be[10]*CM[0]* Be[4] + Be[11]*CM[2]* Be[5] )*Be[24];
Matrix[ 62] = Matrix[62] + ( Be[10]*CM[1]* Be[3] + Be[9]*CM[2]* Be[4] )*Be[24];
Matrix[ 63] = Matrix[63] + ( Be[10]*CM[1]* Be[2] + Be[11]*CM[2]* Be[1] )*Be[24];
Matrix[ 64] = Matrix[64] + ( Be[9]*CM[2]* Be[0] + Be[10]*CM[0]* Be[1] + Be[11]*CM[2]* Be[2] )*Be[24];
Matrix[ 65] = Matrix[65] + ( Be[10]*CM[1]* Be[0] + Be[9]*CM[2]* Be[1] )*Be[24];
Matrix[ 66] = Matrix[66] + ( Be[9]*CM[2]* Be[9] + Be[10]*CM[2]* Be[10] + Be[11]*CM[0]* Be[11] )*Be[24];
Matrix[ 67] = Matrix[67] + ( Be[11]*CM[1]* Be[10] + Be[10]*CM[2]* Be[11] )*Be[24];
Matrix[ 68] = Matrix[68] + ( Be[11]*CM[1]* Be[9] + Be[9]*CM[2]* Be[11] )*Be[24];
Matrix[ 69] = Matrix[69] + ( Be[9]*CM[2]* Be[6] + Be[10]*CM[2]* Be[7] + Be[11]*CM[0]* Be[8] )*Be[24];
Matrix[ 70] = Matrix[70] + ( Be[11]*CM[1]* Be[7] + Be[10]*CM[2]* Be[8] )*Be[24];
Matrix[ 71] = Matrix[71] + ( Be[11]*CM[1]* Be[6] + Be[9]*CM[2]* Be[8] )*Be[24];
Matrix[ 72] = Matrix[72] + ( Be[9]*CM[2]* Be[3] + Be[10]*CM[2]* Be[4] + Be[11]*CM[0]* Be[5] )*Be[24];
Matrix[ 73] = Matrix[73] + ( Be[11]*CM[1]* Be[4] + Be[10]*CM[2]* Be[5] )*Be[24];
Matrix[ 74] = Matrix[74] + ( Be[11]*CM[1]* Be[3] + Be[9]*CM[2]* Be[5] )*Be[24];
Matrix[ 75] = Matrix[75] + ( Be[9]*CM[2]* Be[0] + Be[10]*CM[2]* Be[1] + Be[11]*CM[0]* Be[2] )*Be[24];
Matrix[ 76] = Matrix[76] + ( Be[11]*CM[1]* Be[1] + Be[10]*CM[2]* Be[2] )*Be[24];
Matrix[ 77] = Matrix[77] + ( Be[11]*CM[1]* Be[0] + Be[9]*CM[2]* Be[2] )*Be[24];
Matrix[ 78] = Matrix[78] + ( Be[12]*CM[0]* Be[12] + Be[13]*CM[2]* Be[13] + Be[14]*CM[2]* Be[14] )*Be[24];
Matrix[ 79] = Matrix[79] + ( Be[12]*CM[1]* Be[11] + Be[14]*CM[2]* Be[9] )*Be[24];
Matrix[ 80] = Matrix[80] + ( Be[12]*CM[1]* Be[10] + Be[13]*CM[2]* Be[9] )*Be[24];
Matrix[ 81] = Matrix[81] + ( Be[12]*CM[0]* Be[9] + Be[13]*CM[2]* Be[10] + Be[14]*CM[2]* Be[11] )*Be[24];
Matrix[ 82] = Matrix[82] + ( Be[12]*CM[1]* Be[8] + Be[14]*CM[2]* Be[6] )*Be[24];
Matrix[ 83] = Matrix[83] + ( Be[12]*CM[1]* Be[7] + Be[13]*CM[2]* Be[6] )*Be[24];
Matrix[ 84] = Matrix[84] + ( Be[12]*CM[0]* Be[6] + Be[13]*CM[2]* Be[7] + Be[14]*CM[2]* Be[8] )*Be[24];
Matrix[ 85] = Matrix[85] + ( Be[12]*CM[1]* Be[5] + Be[14]*CM[2]* Be[3] )*Be[24];
Matrix[ 86] = Matrix[86] + ( Be[12]*CM[1]* Be[4] + Be[13]*CM[2]* Be[3] )*Be[24];
Matrix[ 87] = Matrix[87] + ( Be[12]*CM[0]* Be[3] + Be[13]*CM[2]* Be[4] + Be[14]*CM[2]* Be[5] )*Be[24];
Matrix[ 88] = Matrix[88] + ( Be[12]*CM[1]* Be[2] + Be[14]*CM[2]* Be[0] )*Be[24];
Matrix[ 89] = Matrix[89] + ( Be[12]*CM[1]* Be[1] + Be[13]*CM[2]* Be[0] )*Be[24];
Matrix[ 90] = Matrix[90] + ( Be[12]*CM[0]* Be[0] + Be[13]*CM[2]* Be[1] + Be[14]*CM[2]* Be[2] )*Be[24];
Matrix[ 91] = Matrix[91] + ( Be[12]*CM[2]* Be[12] + Be[13]*CM[0]* Be[13] + Be[14]*CM[2]* Be[14] )*Be[24];
Matrix[ 92] = Matrix[92] + ( Be[13]*CM[1]* Be[12] + Be[12]*CM[2]* Be[13] )*Be[24];
Matrix[ 93] = Matrix[93] + ( Be[13]*CM[1]* Be[11] + Be[14]*CM[2]* Be[10] )*Be[24];
Matrix[ 94] = Matrix[94] + ( Be[12]*CM[2]* Be[9] + Be[13]*CM[0]* Be[10] + Be[14]*CM[2]* Be[11] )*Be[24];
Matrix[ 95] = Matrix[95] + ( Be[13]*CM[1]* Be[9] + Be[12]*CM[2]* Be[10] )*Be[24];
Matrix[ 96] = Matrix[96] + ( Be[13]*CM[1]* Be[8] + Be[14]*CM[2]* Be[7] )*Be[24];
Matrix[ 97] = Matrix[97] + ( Be[12]*CM[2]* Be[6] + Be[13]*CM[0]* Be[7] + Be[14]*CM[2]* Be[8] )*Be[24];
Matrix[ 98] = Matrix[98] + ( Be[13]*CM[1]* Be[6] + Be[12]*CM[2]* Be[7] )*Be[24];
Matrix[ 99] = Matrix[99] + ( Be[13]*CM[1]* Be[5] + Be[14]*CM[2]* Be[4] )*Be[24];
Matrix[100] = Matrix[100] + ( Be[12]*CM[2]* Be[3] + Be[13]*CM[0]* Be[4] + Be[14]*CM[2]* Be[5] )*Be[24];
Matrix[101] = Matrix[101] + ( Be[13]*CM[1]* Be[3] + Be[12]*CM[2]* Be[4] )*Be[24];
Matrix[102] = Matrix[102] + ( Be[13]*CM[1]* Be[2] + Be[14]*CM[2]* Be[1] )*Be[24];
Matrix[103] = Matrix[103] + ( Be[12]*CM[2]* Be[0] + Be[13]*CM[0]* Be[1] + Be[14]*CM[2]* Be[2] )*Be[24];
Matrix[104] = Matrix[104] + ( Be[13]*CM[1]* Be[0] + Be[12]*CM[2]* Be[1] )*Be[24];
Matrix[105] = Matrix[105] + ( Be[12]*CM[2]* Be[12] + Be[13]*CM[2]* Be[13] + Be[14]*CM[0]* Be[14] )*Be[24];
Matrix[106] = Matrix[106] + ( Be[14]*CM[1]* Be[13] + Be[13]*CM[2]* Be[14] )*Be[24];
Matrix[107] = Matrix[107] + ( Be[14]*CM[1]* Be[12] + Be[12]*CM[2]* Be[14] )*Be[24];
Matrix[108] = Matrix[108] + ( Be[12]*CM[2]* Be[9] + Be[13]*CM[2]* Be[10] + Be[14]*CM[0]* Be[11] )*Be[24];
Matrix[109] = Matrix[109] + ( Be[14]*CM[1]* Be[10] + Be[13]*CM[2]* Be[11] )*Be[24];
Matrix[110] = Matrix[110] + ( Be[14]*CM[1]* Be[9] + Be[12]*CM[2]* Be[11] )*Be[24];
Matrix[111] = Matrix[111] + ( Be[12]*CM[2]* Be[6] + Be[13]*CM[2]* Be[7] + Be[14]*CM[0]* Be[8] )*Be[24];
Matrix[112] = Matrix[112] + ( Be[14]*CM[1]* Be[7] + Be[13]*CM[2]* Be[8] )*Be[24];
Matrix[113] = Matrix[113] + ( Be[14]*CM[1]* Be[6] + Be[12]*CM[2]* Be[8] )*Be[24];
Matrix[114] = Matrix[114] + ( Be[12]*CM[2]* Be[3] + Be[13]*CM[2]* Be[4] + Be[14]*CM[0]* Be[5] )*Be[24];
Matrix[115] = Matrix[115] + ( Be[14]*CM[1]* Be[4] + Be[13]*CM[2]* Be[5] )*Be[24];
Matrix[116] = Matrix[116] + ( Be[14]*CM[1]* Be[3] + Be[12]*CM[2]* Be[5] )*Be[24];
Matrix[117] = Matrix[117] + ( Be[12]*CM[2]* Be[0] + Be[13]*CM[2]* Be[1] + Be[14]*CM[0]* Be[2] )*Be[24];
Matrix[118] = Matrix[118] + ( Be[14]*CM[1]* Be[1] + Be[13]*CM[2]* Be[2] )*Be[24];
Matrix[119] = Matrix[119] + ( Be[14]*CM[1]* Be[0] + Be[12]*CM[2]* Be[2] )*Be[24];
Matrix[120] = Matrix[120] + ( Be[15]*CM[0]* Be[15] + Be[16]*CM[2]* Be[16] + Be[17]*CM[2]* Be[17] )*Be[24];
Matrix[121] = Matrix[121] + ( Be[15]*CM[1]* Be[14] + Be[17]*CM[2]* Be[12] )*Be[24];
Matrix[122] = Matrix[122] + ( Be[15]*CM[1]* Be[13] + Be[16]*CM[2]* Be[12] )*Be[24];
Matrix[123] = Matrix[123] + ( Be[15]*CM[0]* Be[12] + Be[16]*CM[2]* Be[13] + Be[17]*CM[2]* Be[14] )*Be[24];
Matrix[124] = Matrix[124] + ( Be[15]*CM[1]* Be[11] + Be[17]*CM[2]* Be[9] )*Be[24];
Matrix[125] = Matrix[125] + ( Be[15]*CM[1]* Be[10] + Be[16]*CM[2]* Be[9] )*Be[24];
Matrix[126] = Matrix[126] + ( Be[15]*CM[0]* Be[9] + Be[16]*CM[2]* Be[10] + Be[17]*CM[2]* Be[11] )*Be[24];
Matrix[127] = Matrix[127] + ( Be[15]*CM[1]* Be[8] + Be[17]*CM[2]* Be[6] )*Be[24];
Matrix[128] = Matrix[128] + ( Be[15]*CM[1]* Be[7] + Be[16]*CM[2]* Be[6] )*Be[24];
Matrix[129] = Matrix[129] + ( Be[15]*CM[0]* Be[6] + Be[16]*CM[2]* Be[7] + Be[17]*CM[2]* Be[8] )*Be[24];
Matrix[130] = Matrix[130] + ( Be[15]*CM[1]* Be[5] + Be[17]*CM[2]* Be[3] )*Be[24];
Matrix[131] = Matrix[131] + ( Be[15]*CM[1]* Be[4] + Be[16]*CM[2]* Be[3] )*Be[24];
Matrix[132] = Matrix[132] + ( Be[15]*CM[0]* Be[3] + Be[16]*CM[2]* Be[4] + Be[17]*CM[2]* Be[5] )*Be[24];
Matrix[133] = Matrix[133] + ( Be[15]*CM[1]* Be[2] + Be[17]*CM[2]* Be[0] )*Be[24];
Matrix[134] = Matrix[134] + ( Be[15]*CM[1]* Be[1] + Be[16]*CM[2]* Be[0] )*Be[24];
Matrix[135] = Matrix[135] + ( Be[15]*CM[0]* Be[0] + Be[16]*CM[2]* Be[1] + Be[17]*CM[2]* Be[2] )*Be[24];
Matrix[136] = Matrix[136] + ( Be[15]*CM[2]* Be[15] + Be[16]*CM[0]* Be[16] + Be[17]*CM[2]* Be[17] )*Be[24];
Matrix[137] = Matrix[137] + ( Be[16]*CM[1]* Be[15] + Be[15]*CM[2]* Be[16] )*Be[24];
Matrix[138] = Matrix[138] + ( Be[16]*CM[1]* Be[14] + Be[17]*CM[2]* Be[13] )*Be[24];
Matrix[139] = Matrix[139] + ( Be[15]*CM[2]* Be[12] + Be[16]*CM[0]* Be[13] + Be[17]*CM[2]* Be[14] )*Be[24];
Matrix[140] = Matrix[140] + ( Be[16]*CM[1]* Be[12] + Be[15]*CM[2]* Be[13] )*Be[24];
Matrix[141] = Matrix[141] + ( Be[16]*CM[1]* Be[11] + Be[17]*CM[2]* Be[10] )*Be[24];
Matrix[142] = Matrix[142] + ( Be[15]*CM[2]* Be[9] + Be[16]*CM[0]* Be[10] + Be[17]*CM[2]* Be[11] )*Be[24];
Matrix[143] = Matrix[143] + ( Be[16]*CM[1]* Be[9] + Be[15]*CM[2]* Be[10] )*Be[24];
Matrix[144] = Matrix[144] + ( Be[16]*CM[1]* Be[8] + Be[17]*CM[2]* Be[7] )*Be[24];
Matrix[145] = Matrix[145] + ( Be[15]*CM[2]* Be[6] + Be[16]*CM[0]* Be[7] + Be[17]*CM[2]* Be[8] )*Be[24];
Matrix[146] = Matrix[146] + ( Be[16]*CM[1]* Be[6] + Be[15]*CM[2]* Be[7] )*Be[24];
Matrix[147] = Matrix[147] + ( Be[16]*CM[1]* Be[5] + Be[17]*CM[2]* Be[4] )*Be[24];
Matrix[148] = Matrix[148] + ( Be[15]*CM[2]* Be[3] + Be[16]*CM[0]* Be[4] + Be[17]*CM[2]* Be[5] )*Be[24];
Matrix[149] = Matrix[149] + ( Be[16]*CM[1]* Be[3] + Be[15]*CM[2]* Be[4] )*Be[24];
Matrix[150] = Matrix[150] + ( Be[16]*CM[1]* Be[2] + Be[17]*CM[2]* Be[1] )*Be[24];
Matrix[151] = Matrix[151] + ( Be[15]*CM[2]* Be[0] + Be[16]*CM[0]* Be[1] + Be[17]*CM[2]* Be[2] )*Be[24];
Matrix[152] = Matrix[152] + ( Be[16]*CM[1]* Be[0] + Be[15]*CM[2]* Be[1] )*Be[24];
Matrix[153] = Matrix[153] + ( Be[15]*CM[2]* Be[15] + Be[16]*CM[2]* Be[16] + Be[17]*CM[0]* Be[17] )*Be[24];
Matrix[154] = Matrix[154] + ( Be[17]*CM[1]* Be[16] + Be[16]*CM[2]* Be[17] )*Be[24];
Matrix[155] = Matrix[155] + ( Be[17]*CM[1]* Be[15] + Be[15]*CM[2]* Be[17] )*Be[24];
Matrix[156] = Matrix[156] + ( Be[15]*CM[2]* Be[12] + Be[16]*CM[2]* Be[13] + Be[17]*CM[0]* Be[14] )*Be[24];
Matrix[157] = Matrix[157] + ( Be[17]*CM[1]* Be[13] + Be[16]*CM[2]* Be[14] )*Be[24];
Matrix[158] = Matrix[158] + ( Be[17]*CM[1]* Be[12] + Be[15]*CM[2]* Be[14] )*Be[24];
Matrix[159] = Matrix[159] + ( Be[15]*CM[2]* Be[9] + Be[16]*CM[2]* Be[10] + Be[17]*CM[0]* Be[11] )*Be[24];
Matrix[160] = Matrix[160] + ( Be[17]*CM[1]* Be[10] + Be[16]*CM[2]* Be[11] )*Be[24];
Matrix[161] = Matrix[161] + ( Be[17]*CM[1]* Be[9] + Be[15]*CM[2]* Be[11] )*Be[24];
Matrix[162] = Matrix[162] + ( Be[15]*CM[2]* Be[6] + Be[16]*CM[2]* Be[7] + Be[17]*CM[0]* Be[8] )*Be[24];
Matrix[163] = Matrix[163] + ( Be[17]*CM[1]* Be[7] + Be[16]*CM[2]* Be[8] )*Be[24];
Matrix[164] = Matrix[164] + ( Be[17]*CM[1]* Be[6] + Be[15]*CM[2]* Be[8] )*Be[24];
Matrix[165] = Matrix[165] + ( Be[15]*CM[2]* Be[3] + Be[16]*CM[2]* Be[4] + Be[17]*CM[0]* Be[5] )*Be[24];
Matrix[166] = Matrix[166] + ( Be[17]*CM[1]* Be[4] + Be[16]*CM[2]* Be[5] )*Be[24];
Matrix[167] = Matrix[167] + ( Be[17]*CM[1]* Be[3] + Be[15]*CM[2]* Be[5] )*Be[24];
Matrix[168] = Matrix[168] + ( Be[15]*CM[2]* Be[0] + Be[16]*CM[2]* Be[1] + Be[17]*CM[0]* Be[2] )*Be[24];
Matrix[169] = Matrix[169] + ( Be[17]*CM[1]* Be[1] + Be[16]*CM[2]* Be[2] )*Be[24];
Matrix[170] = Matrix[170] + ( Be[17]*CM[1]* Be[0] + Be[15]*CM[2]* Be[2] )*Be[24];
Matrix[171] = Matrix[171] + ( Be[18]*CM[0]* Be[18] + Be[19]*CM[2]* Be[19] + Be[20]*CM[2]* Be[20] )*Be[24];
Matrix[172] = Matrix[172] + ( Be[18]*CM[1]* Be[17] + Be[20]*CM[2]* Be[15] )*Be[24];
Matrix[173] = Matrix[173] + ( Be[18]*CM[1]* Be[16] + Be[19]*CM[2]* Be[15] )*Be[24];
Matrix[174] = Matrix[174] + ( Be[18]*CM[0]* Be[15] + Be[19]*CM[2]* Be[16] + Be[20]*CM[2]* Be[17] )*Be[24];
Matrix[175] = Matrix[175] + ( Be[18]*CM[1]* Be[14] + Be[20]*CM[2]* Be[12] )*Be[24];
Matrix[176] = Matrix[176] + ( Be[18]*CM[1]* Be[13] + Be[19]*CM[2]* Be[12] )*Be[24];
Matrix[177] = Matrix[177] + ( Be[18]*CM[0]* Be[12] + Be[19]*CM[2]* Be[13] + Be[20]*CM[2]* Be[14] )*Be[24];
Matrix[178] = Matrix[178] + ( Be[18]*CM[1]* Be[11] + Be[20]*CM[2]* Be[9] )*Be[24];
Matrix[179] = Matrix[179] + ( Be[18]*CM[1]* Be[10] + Be[19]*CM[2]* Be[9] )*Be[24];
Matrix[180] = Matrix[180] + ( Be[18]*CM[0]* Be[9] + Be[19]*CM[2]* Be[10] + Be[20]*CM[2]* Be[11] )*Be[24];
Matrix[181] = Matrix[181] + ( Be[18]*CM[1]* Be[8] + Be[20]*CM[2]* Be[6] )*Be[24];
Matrix[182] = Matrix[182] + ( Be[18]*CM[1]* Be[7] + Be[19]*CM[2]* Be[6] )*Be[24];
Matrix[183] = Matrix[183] + ( Be[18]*CM[0]* Be[6] + Be[19]*CM[2]* Be[7] + Be[20]*CM[2]* Be[8] )*Be[24];
Matrix[184] = Matrix[184] + ( Be[18]*CM[1]* Be[5] + Be[20]*CM[2]* Be[3] )*Be[24];
Matrix[185] = Matrix[185] + ( Be[18]*CM[1]* Be[4] + Be[19]*CM[2]* Be[3] )*Be[24];
Matrix[186] = Matrix[186] + ( Be[18]*CM[0]* Be[3] + Be[19]*CM[2]* Be[4] + Be[20]*CM[2]* Be[5] )*Be[24];
Matrix[187] = Matrix[187] + ( Be[18]*CM[1]* Be[2] + Be[20]*CM[2]* Be[0] )*Be[24];
Matrix[188] = Matrix[188] + ( Be[18]*CM[1]* Be[1] + Be[19]*CM[2]* Be[0] )*Be[24];
Matrix[189] = Matrix[189] + ( Be[18]*CM[0]* Be[0] + Be[19]*CM[2]* Be[1] + Be[20]*CM[2]* Be[2] )*Be[24];
Matrix[190] = Matrix[190] + ( Be[18]*CM[2]* Be[18] + Be[19]*CM[0]* Be[19] + Be[20]*CM[2]* Be[20] )*Be[24];
Matrix[191] = Matrix[191] + ( Be[19]*CM[1]* Be[18] + Be[18]*CM[2]* Be[19] )*Be[24];
Matrix[192] = Matrix[192] + ( Be[19]*CM[1]* Be[17] + Be[20]*CM[2]* Be[16] )*Be[24];
Matrix[193] = Matrix[193] + ( Be[18]*CM[2]* Be[15] + Be[19]*CM[0]* Be[16] + Be[20]*CM[2]* Be[17] )*Be[24];
Matrix[194] = Matrix[194] + ( Be[19]*CM[1]* Be[15] + Be[18]*CM[2]* Be[16] )*Be[24];
Matrix[195] = Matrix[195] + ( Be[19]*CM[1]* Be[14] + Be[20]*CM[2]* Be[13] )*Be[24];
Matrix[196] = Matrix[196] + ( Be[18]*CM[2]* Be[12] + Be[19]*CM[0]* Be[13] + Be[20]*CM[2]* Be[14] )*Be[24];
Matrix[197] = Matrix[197] + ( Be[19]*CM[1]* Be[12] + Be[18]*CM[2]* Be[13] )*Be[24];
Matrix[198] = Matrix[198] + ( Be[19]*CM[1]* Be[11] + Be[20]*CM[2]* Be[10] )*Be[24];
Matrix[199] = Matrix[199] + ( Be[18]*CM[2]* Be[9] + Be[19]*CM[0]* Be[10] + Be[20]*CM[2]* Be[11] )*Be[24];
Matrix[200] = Matrix[200] + ( Be[19]*CM[1]* Be[9] + Be[18]*CM[2]* Be[10] )*Be[24];
Matrix[201] = Matrix[201] + ( Be[19]*CM[1]* Be[8] + Be[20]*CM[2]* Be[7] )*Be[24];
Matrix[202] = Matrix[202] + ( Be[18]*CM[2]* Be[6] + Be[19]*CM[0]* Be[7] + Be[20]*CM[2]* Be[8] )*Be[24];
Matrix[203] = Matrix[203] + ( Be[19]*CM[1]* Be[6] + Be[18]*CM[2]* Be[7] )*Be[24];
Matrix[204] = Matrix[204] + ( Be[19]*CM[1]* Be[5] + Be[20]*CM[2]* Be[4] )*Be[24];
Matrix[205] = Matrix[205] + ( Be[18]*CM[2]* Be[3] + Be[19]*CM[0]* Be[4] + Be[20]*CM[2]* Be[5] )*Be[24];
Matrix[206] = Matrix[206] + ( Be[19]*CM[1]* Be[3] + Be[18]*CM[2]* Be[4] )*Be[24];
Matrix[207] = Matrix[207] + ( Be[19]*CM[1]* Be[2] + Be[20]*CM[2]* Be[1] )*Be[24];
Matrix[208] = Matrix[208] + ( Be[18]*CM[2]* Be[0] + Be[19]*CM[0]* Be[1] + Be[20]*CM[2]* Be[2] )*Be[24];
Matrix[209] = Matrix[209] + ( Be[19]*CM[1]* Be[0] + Be[18]*CM[2]* Be[1] )*Be[24];
Matrix[210] = Matrix[210] + ( Be[18]*CM[2]* Be[18] + Be[19]*CM[2]* Be[19] + Be[20]*CM[0]* Be[20] )*Be[24];
Matrix[211] = Matrix[211] + ( Be[20]*CM[1]* Be[19] + Be[19]*CM[2]* Be[20] )*Be[24];
Matrix[212] = Matrix[212] + ( Be[20]*CM[1]* Be[18] + Be[18]*CM[2]* Be[20] )*Be[24];
Matrix[213] = Matrix[213] + ( Be[18]*CM[2]* Be[15] + Be[19]*CM[2]* Be[16] + Be[20]*CM[0]* Be[17] )*Be[24];
Matrix[214] = Matrix[214] + ( Be[20]*CM[1]* Be[16] + Be[19]*CM[2]* Be[17] )*Be[24];
Matrix[215] = Matrix[215] + ( Be[20]*CM[1]* Be[15] + Be[18]*CM[2]* Be[17] )*Be[24];
Matrix[216] = Matrix[216] + ( Be[18]*CM[2]* Be[12] + Be[19]*CM[2]* Be[13] + Be[20]*CM[0]* Be[14] )*Be[24];
Matrix[217] = Matrix[217] + ( Be[20]*CM[1]* Be[13] + Be[19]*CM[2]* Be[14] )*Be[24];
Matrix[218] = Matrix[218] + ( Be[20]*CM[1]* Be[12] + Be[18]*CM[2]* Be[14] )*Be[24];
Matrix[219] = Matrix[219] + ( Be[18]*CM[2]* Be[9] + Be[19]*CM[2]* Be[10] + Be[20]*CM[0]* Be[11] )*Be[24];
Matrix[220] = Matrix[220] + ( Be[20]*CM[1]* Be[10] + Be[19]*CM[2]* Be[11] )*Be[24];
Matrix[221] = Matrix[221] + ( Be[20]*CM[1]* Be[9] + Be[18]*CM[2]* Be[11] )*Be[24];
Matrix[222] = Matrix[222] + ( Be[18]*CM[2]* Be[6] + Be[19]*CM[2]* Be[7] + Be[20]*CM[0]* Be[8] )*Be[24];
Matrix[223] = Matrix[223] + ( Be[20]*CM[1]* Be[7] + Be[19]*CM[2]* Be[8] )*Be[24];
Matrix[224] = Matrix[224] + ( Be[20]*CM[1]* Be[6] + Be[18]*CM[2]* Be[8] )*Be[24];
Matrix[225] = Matrix[225] + ( Be[18]*CM[2]* Be[3] + Be[19]*CM[2]* Be[4] + Be[20]*CM[0]* Be[5] )*Be[24];
Matrix[226] = Matrix[226] + ( Be[20]*CM[1]* Be[4] + Be[19]*CM[2]* Be[5] )*Be[24];
Matrix[227] = Matrix[227] + ( Be[20]*CM[1]* Be[3] + Be[18]*CM[2]* Be[5] )*Be[24];
Matrix[228] = Matrix[228] + ( Be[18]*CM[2]* Be[0] + Be[19]*CM[2]* Be[1] + Be[20]*CM[0]* Be[2] )*Be[24];
Matrix[229] = Matrix[229] + ( Be[20]*CM[1]* Be[1] + Be[19]*CM[2]* Be[2] )*Be[24];
Matrix[230] = Matrix[230] + ( Be[20]*CM[1]* Be[0] + Be[18]*CM[2]* Be[2] )*Be[24];
Matrix[231] = Matrix[231] + ( Be[21]*CM[0]* Be[21] + Be[22]*CM[2]* Be[22] + Be[23]*CM[2]* Be[23] )*Be[24];
Matrix[232] = Matrix[232] + ( Be[21]*CM[1]* Be[20] + Be[23]*CM[2]* Be[18] )*Be[24];
Matrix[233] = Matrix[233] + ( Be[21]*CM[1]* Be[19] + Be[22]*CM[2]* Be[18] )*Be[24];
Matrix[234] = Matrix[234] + ( Be[21]*CM[0]* Be[18] + Be[22]*CM[2]* Be[19] + Be[23]*CM[2]* Be[20] )*Be[24];
Matrix[235] = Matrix[235] + ( Be[21]*CM[1]* Be[17] + Be[23]*CM[2]* Be[15] )*Be[24];
Matrix[236] = Matrix[236] + ( Be[21]*CM[1]* Be[16] + Be[22]*CM[2]* Be[15] )*Be[24];
Matrix[237] = Matrix[237] + ( Be[21]*CM[0]* Be[15] + Be[22]*CM[2]* Be[16] + Be[23]*CM[2]* Be[17] )*Be[24];
Matrix[238] = Matrix[238] + ( Be[21]*CM[1]* Be[14] + Be[23]*CM[2]* Be[12] )*Be[24];
Matrix[239] = Matrix[239] + ( Be[21]*CM[1]* Be[13] + Be[22]*CM[2]* Be[12] )*Be[24];
Matrix[240] = Matrix[240] + ( Be[21]*CM[0]* Be[12] + Be[22]*CM[2]* Be[13] + Be[23]*CM[2]* Be[14] )*Be[24];
Matrix[241] = Matrix[241] + ( Be[21]*CM[1]* Be[11] + Be[23]*CM[2]* Be[9] )*Be[24];
Matrix[242] = Matrix[242] + ( Be[21]*CM[1]* Be[10] + Be[22]*CM[2]* Be[9] )*Be[24];
Matrix[243] = Matrix[243] + ( Be[21]*CM[0]* Be[9] + Be[22]*CM[2]* Be[10] + Be[23]*CM[2]* Be[11] )*Be[24];
Matrix[244] = Matrix[244] + ( Be[21]*CM[1]* Be[8] + Be[23]*CM[2]* Be[6] )*Be[24];
Matrix[245] = Matrix[245] + ( Be[21]*CM[1]* Be[7] + Be[22]*CM[2]* Be[6] )*Be[24];
Matrix[246] = Matrix[246] + ( Be[21]*CM[0]* Be[6] + Be[22]*CM[2]* Be[7] + Be[23]*CM[2]* Be[8] )*Be[24];
Matrix[247] = Matrix[247] + ( Be[21]*CM[1]* Be[5] + Be[23]*CM[2]* Be[3] )*Be[24];
Matrix[248] = Matrix[248] + ( Be[21]*CM[1]* Be[4] + Be[22]*CM[2]* Be[3] )*Be[24];
Matrix[249] = Matrix[249] + ( Be[21]*CM[0]* Be[3] + Be[22]*CM[2]* Be[4] + Be[23]*CM[2]* Be[5] )*Be[24];
Matrix[250] = Matrix[250] + ( Be[21]*CM[1]* Be[2] + Be[23]*CM[2]* Be[0] )*Be[24];
Matrix[251] = Matrix[251] + ( Be[21]*CM[1]* Be[1] + Be[22]*CM[2]* Be[0] )*Be[24];
Matrix[252] = Matrix[252] + ( Be[21]*CM[0]* Be[0] + Be[22]*CM[2]* Be[1] + Be[23]*CM[2]* Be[2] )*Be[24];
Matrix[253] = Matrix[253] + ( Be[21]*CM[2]* Be[21] + Be[22]*CM[0]* Be[22] + Be[23]*CM[2]* Be[23] )*Be[24];
Matrix[254] = Matrix[254] + ( Be[22]*CM[1]* Be[21] + Be[21]*CM[2]* Be[22] )*Be[24];
Matrix[255] = Matrix[255] + ( Be[22]*CM[1]* Be[20] + Be[23]*CM[2]* Be[19] )*Be[24];
Matrix[256] = Matrix[256] + ( Be[21]*CM[2]* Be[18] + Be[22]*CM[0]* Be[19] + Be[23]*CM[2]* Be[20] )*Be[24];
Matrix[257] = Matrix[257] + ( Be[22]*CM[1]* Be[18] + Be[21]*CM[2]* Be[19] )*Be[24];
Matrix[258] = Matrix[258] + ( Be[22]*CM[1]* Be[17] + Be[23]*CM[2]* Be[16] )*Be[24];
Matrix[259] = Matrix[259] + ( Be[21]*CM[2]* Be[15] + Be[22]*CM[0]* Be[16] + Be[23]*CM[2]* Be[17] )*Be[24];
Matrix[260] = Matrix[260] + ( Be[22]*CM[1]* Be[15] + Be[21]*CM[2]* Be[16] )*Be[24];
Matrix[261] = Matrix[261] + ( Be[22]*CM[1]* Be[14] + Be[23]*CM[2]* Be[13] )*Be[24];
Matrix[262] = Matrix[262] + ( Be[21]*CM[2]* Be[12] + Be[22]*CM[0]* Be[13] + Be[23]*CM[2]* Be[14] )*Be[24];
Matrix[263] = Matrix[263] + ( Be[22]*CM[1]* Be[12] + Be[21]*CM[2]* Be[13] )*Be[24];
Matrix[264] = Matrix[264] + ( Be[22]*CM[1]* Be[11] + Be[23]*CM[2]* Be[10] )*Be[24];
Matrix[265] = Matrix[265] + ( Be[21]*CM[2]* Be[9] + Be[22]*CM[0]* Be[10] + Be[23]*CM[2]* Be[11] )*Be[24];
Matrix[266] = Matrix[266] + ( Be[22]*CM[1]* Be[9] + Be[21]*CM[2]* Be[10] )*Be[24];
Matrix[267] = Matrix[267] + ( Be[22]*CM[1]* Be[8] + Be[23]*CM[2]* Be[7] )*Be[24];
Matrix[268] = Matrix[268] + ( Be[21]*CM[2]* Be[6] + Be[22]*CM[0]* Be[7] + Be[23]*CM[2]* Be[8] )*Be[24];
Matrix[269] = Matrix[269] + ( Be[22]*CM[1]* Be[6] + Be[21]*CM[2]* Be[7] )*Be[24];
Matrix[270] = Matrix[270] + ( Be[22]*CM[1]* Be[5] + Be[23]*CM[2]* Be[4] )*Be[24];
Matrix[271] = Matrix[271] + ( Be[21]*CM[2]* Be[3] + Be[22]*CM[0]* Be[4] + Be[23]*CM[2]* Be[5] )*Be[24];
Matrix[272] = Matrix[272] + ( Be[22]*CM[1]* Be[3] + Be[21]*CM[2]* Be[4] )*Be[24];
Matrix[273] = Matrix[273] + ( Be[22]*CM[1]* Be[2] + Be[23]*CM[2]* Be[1] )*Be[24];
Matrix[274] = Matrix[274] + ( Be[21]*CM[2]* Be[0] + Be[22]*CM[0]* Be[1] + Be[23]*CM[2]* Be[2] )*Be[24];
Matrix[275] = Matrix[275] + ( Be[22]*CM[1]* Be[0] + Be[21]*CM[2]* Be[1] )*Be[24];
Matrix[276] = Matrix[276] + ( Be[21]*CM[2]* Be[21] + Be[22]*CM[2]* Be[22] + Be[23]*CM[0]* Be[23] )*Be[24];
Matrix[277] = Matrix[277] + ( Be[23]*CM[1]* Be[22] + Be[22]*CM[2]* Be[23] )*Be[24];
Matrix[278] = Matrix[278] + ( Be[23]*CM[1]* Be[21] + Be[21]*CM[2]* Be[23] )*Be[24];
Matrix[279] = Matrix[279] + ( Be[21]*CM[2]* Be[18] + Be[22]*CM[2]* Be[19] + Be[23]*CM[0]* Be[20] )*Be[24];
Matrix[280] = Matrix[280] + ( Be[23]*CM[1]* Be[19] + Be[22]*CM[2]* Be[20] )*Be[24];
Matrix[281] = Matrix[281] + ( Be[23]*CM[1]* Be[18] + Be[21]*CM[2]* Be[20] )*Be[24];
Matrix[282] = Matrix[282] + ( Be[21]*CM[2]* Be[15] + Be[22]*CM[2]* Be[16] + Be[23]*CM[0]* Be[17] )*Be[24];
Matrix[283] = Matrix[283] + ( Be[23]*CM[1]* Be[16] + Be[22]*CM[2]* Be[17] )*Be[24];
Matrix[284] = Matrix[284] + ( Be[23]*CM[1]* Be[15] + Be[21]*CM[2]* Be[17] )*Be[24];
Matrix[285] = Matrix[285] + ( Be[21]*CM[2]* Be[12] + Be[22]*CM[2]* Be[13] + Be[23]*CM[0]* Be[14] )*Be[24];
Matrix[286] = Matrix[286] + ( Be[23]*CM[1]* Be[13] + Be[22]*CM[2]* Be[14] )*Be[24];
Matrix[287] = Matrix[287] + ( Be[23]*CM[1]* Be[12] + Be[21]*CM[2]* Be[14] )*Be[24];
Matrix[288] = Matrix[288] + ( Be[21]*CM[2]* Be[9] + Be[22]*CM[2]* Be[10] + Be[23]*CM[0]* Be[11] )*Be[24];
Matrix[289] = Matrix[289] + ( Be[23]*CM[1]* Be[10] + Be[22]*CM[2]* Be[11] )*Be[24];
Matrix[290] = Matrix[290] + ( Be[23]*CM[1]* Be[9] + Be[21]*CM[2]* Be[11] )*Be[24];
Matrix[291] = Matrix[291] + ( Be[21]*CM[2]* Be[6] + Be[22]*CM[2]* Be[7] + Be[23]*CM[0]* Be[8] )*Be[24];
Matrix[292] = Matrix[292] + ( Be[23]*CM[1]* Be[7] + Be[22]*CM[2]* Be[8] )*Be[24];
Matrix[293] = Matrix[293] + ( Be[23]*CM[1]* Be[6] + Be[21]*CM[2]* Be[8] )*Be[24];
Matrix[294] = Matrix[294] + ( Be[21]*CM[2]* Be[3] + Be[22]*CM[2]* Be[4] + Be[23]*CM[0]* Be[5] )*Be[24];
Matrix[295] = Matrix[295] + ( Be[23]*CM[1]* Be[4] + Be[22]*CM[2]* Be[5] )*Be[24];
Matrix[296] = Matrix[296] + ( Be[23]*CM[1]* Be[3] + Be[21]*CM[2]* Be[5] )*Be[24];
Matrix[297] = Matrix[297] + ( Be[21]*CM[2]* Be[0] + Be[22]*CM[2]* Be[1] + Be[23]*CM[0]* Be[2] )*Be[24];
Matrix[298] = Matrix[298] + ( Be[23]*CM[1]* Be[1] + Be[22]*CM[2]* Be[2] )*Be[24];
Matrix[299] = Matrix[299] + ( Be[23]*CM[1]* Be[0] + Be[21]*CM[2]* Be[2] )*Be[24];
}
|
7bc510dca352b590ee79120941d39089d3ca7520
|
64cbc0ae0e7fe75820ffb2d775db2e31578ff9a5
|
/NetworkIPCServer/server-socket-fork.cpp
|
3cfe99bc8e4f34ef39a66e5afa5042cf52e8e841
|
[] |
no_license
|
lilelr/accumulation-unix-programming
|
12349c847737c31b61d02b91458f0d44855c42cf
|
3a83a4e49cf3eb270a10a260f712c70e71eccae7
|
refs/heads/master
| 2021-01-24T03:49:04.985179
| 2018-06-07T09:45:56
| 2018-06-07T09:45:56
| 122,907,206
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,240
|
cpp
|
server-socket-fork.cpp
|
#include "../NetworkIPCSockets/apue.h"
#include <netdb.h>
#include <errno.h>
#include <syslog.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define QLEN 10
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif
int
initserver(int type, const struct sockaddr *addr, socklen_t alen,
int qlen)
{
int fd, err;
int reuse = 1;
if ((fd = socket(addr->sa_family, type, 0)) < 0)
return(-1);
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(int)) < 0) {
err = errno;
goto errout;
}
if (bind(fd, addr, alen) < 0) {
err = errno;
goto errout;
}
if (type == SOCK_STREAM || type == SOCK_SEQPACKET) {
if (listen(fd, qlen) < 0) {
err = errno;
goto errout;
}
}
return(fd);
errout:
close(fd);
errno = err;
return(-1);
}
void
serve(int sockfd)
{
int clfd, status;
pid_t pid;
for (;;) {
clfd = accept(sockfd, NULL, NULL);
if (clfd < 0) {
syslog(LOG_ERR, "ruptimed: accept error: %s",
strerror(errno));
exit(1);
}
if ((pid = fork()) < 0) {
syslog(LOG_ERR, "ruptimed: fork error: %s",
strerror(errno));
exit(1);
} else if (pid == 0) { /* child */
/*
* The parent called daemonize ({Prog daemoninit}), so
* STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO
* are already open to /dev/null. Thus, the call to
* close doesn't need to be protected by checks that
* clfd isn't already equal to one of these values.
*/
if (dup2(clfd, STDOUT_FILENO) != STDOUT_FILENO ||
dup2(clfd, STDERR_FILENO) != STDERR_FILENO) {
syslog(LOG_ERR, "ruptimed: unexpected error");
exit(1);
}
close(clfd);
// execl("/usr/bin/uptime", "uptime", (char *)0);
// execl("/bin/hostname", "hostname", (char *)0);
// syslog(LOG_ERR, "ruptimed: unexpected return from exec: %s",
// strerror(errno));
// int fd;
// void* buf[512];
// int nread_num;
// int read_times =0;
// if((fd=open("/home/lilelr/HappyNewYear",O_RDONLY)) >= 0){
// while (true){
// nread_num = read(fd,buf,512);
// read_times++;
// if(nread_num!=0){
// write(STDOUT_FILENO,buf,nread_num);
// if(nread_num!=512){
//
//// close(STDOUT_FILENO);
// break;
// }
// }
// }
// close(fd);
// }
printf("I'm B_ubuntu.Who are you?\n");
exit(0);
} else { /* parent */
close(clfd);
waitpid(pid, &status, 0);
}
}
}
int
main(int argc, char *argv[])
{
struct addrinfo *ailist, *aip;
struct addrinfo hint;
int sockfd, err, n;
char *host;
if (argc != 1)
printf("usage: ruptimed");
#ifdef _SC_HOST_NAME_MAX
n = sysconf(_SC_HOST_NAME_MAX);
if (n < 0) /* best guess */
#endif
n = HOST_NAME_MAX;
host = static_cast<char *>(malloc(n));
if (host == NULL)
printf("malloc error");
if (gethostname(host, n) < 0)
printf("gethostname error");
printf("ruptimed");
hint.ai_flags = AI_CANONNAME;
hint.ai_family = 0;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = 0;
hint.ai_addrlen = 0;
hint.ai_canonname = NULL;
hint.ai_addr = NULL;
hint.ai_next = NULL;
if ((err = getaddrinfo(host, "nfs", &hint, &ailist)) != 0) {
syslog(LOG_ERR, "ruptimed: getaddrinfo error: %s",
gai_strerror(err));
exit(1);
}
for (aip = ailist; aip != NULL; aip = aip->ai_next) {
if ((sockfd = initserver(SOCK_STREAM, aip->ai_addr,
aip->ai_addrlen, QLEN)) >= 0) {
serve(sockfd);
exit(0);
}
}
exit(1);
}
|
6793af54d173355827c6b32c8151ff68d4705d96
|
992955baa81b9f4083b0bd494eb6a1b01a155fd1
|
/Networking Project/Networking Project/ServerConenction.cpp
|
f97f3a1084ec5ef792a16c63fdc1131c324be921
|
[] |
no_license
|
MichaelBridgette/Networking-SDL
|
2133b89421d437cb814ca509182548bd904c598f
|
881c5a035b6a745c731745d864d4bc5c2b67131e
|
refs/heads/master
| 2020-04-10T23:44:59.937033
| 2018-12-13T12:56:43
| 2018-12-13T12:56:43
| 161,363,563
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,804
|
cpp
|
ServerConenction.cpp
|
#include "ServerConnection.h"
ServerConnection::ServerConnection()
{
}
ServerConnection::~ServerConnection()
{
}
bool ServerConnection::initialise()
{
std::string serverIp = "149.153.106.151";
int serverPort = 54000;
WSAData data;
WORD ver = MAKEWORD(2, 2);
int wsResult = WSAStartup(ver, &data);
if (wsResult != 0)
{
std::cout << "Can't start Winsock, Err #" << wsResult << std::endl;
return false;
}
// Create socket
m_socket = socket(AF_INET, SOCK_STREAM, 0);
if (m_socket == INVALID_SOCKET)
{
std::cout << "Can't create socket, Err #" << WSAGetLastError() << std::endl;
WSACleanup();
return false;
}
// Make non-locking socket
u_long type = 1;
int result = ioctlsocket(m_socket, FIONBIO, &type);
if (result != NO_ERROR) {
std::cout << "Failed to create non-locking socket, Error: " << result << std::endl;
return false;
}
// Fill in a hint structure
sockaddr_in hint;
hint.sin_family = AF_INET;
hint.sin_port = htons(serverPort);
inet_pton(AF_INET, serverIp.c_str(), &hint.sin_addr);
// Connect to server
int connResult = connect(m_socket, (sockaddr*)&hint, sizeof(hint));
if (connResult == SOCKET_ERROR)
{
// This causes errors
//std::cout << "Can't connect to server, Error: " << WSAGetLastError() << std::endl;
//closesocket(sock);
//WSACleanup();
//return;
}
return true;
}
void ServerConnection::sendMessage(std::string message)
{
send(m_socket, message.c_str(), message.size() + 1, 0);
}
std::string ServerConnection::receiveMessage()
{
ZeroMemory(m_buf, 4096);
int bytesReceived = recv(m_socket, m_buf, 4096, 0);
if (bytesReceived > 0)
{
std::string receivedMessage = std::string(m_buf, 0, bytesReceived);
return receivedMessage;
}
return "";
}
void ServerConnection::end()
{
closesocket(m_socket);
WSACleanup();
}
|
3355abd65e1b6b8f04c976ab901548d67edfe7c6
|
f9c231a866ef7138c033f301becbf24c8bdca633
|
/Test5/tongSoBeHonN.cpp
|
895903e2bf9926383fecf853b7c636b8d37796d2
|
[] |
no_license
|
cuongnh28/DSAFall2019
|
3eef8f5e0e1cbe008bd304c847dd9abaa4ad144f
|
2729d834b3c4a3560bf63aa6d1dcfc7457385246
|
refs/heads/main
| 2023-02-02T14:41:39.353309
| 2020-12-23T16:20:02
| 2020-12-23T16:20:02
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 322
|
cpp
|
tongSoBeHonN.cpp
|
#include<iostream>
using namespace std;
int main(){
int n,F[100][100];
cin>>n;
for(int i=1;i<=n;i++) F[0][i]=0;
F[0][0]=1;
for(int m=1;m<=n;m++){
for(int v=0;v<=n;v++){
if(m>v) F[m][v]=F[m-1][v];
else F[m][v]=F[m-1][v]+F[m][v-m];
}
}
cout<<F[n][n];
}
|
75f0c0d9516d4adb657e11c483c3572eaa34fce2
|
0579f0569b7c29f0bac7118b32b7c36c1c3db606
|
/src/myimagelabel.cpp
|
b364463ce449fb260c9299d25938339d2529febc
|
[
"MIT"
] |
permissive
|
tobiasberling/ImageDiff
|
21564a6f5beacc0f36d221348ec2dc7cb3ff7e2a
|
d3827e8f4d88aab214b32ec93bc09dae62eb9554
|
refs/heads/master
| 2016-09-02T00:16:45.505165
| 2015-06-03T17:44:55
| 2015-06-03T17:44:55
| 36,819,662
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,376
|
cpp
|
myimagelabel.cpp
|
#include "myimagelabel.h"
#include <QDragEnterEvent>
#include <QMimeData>
#include <QImageReader>
#include <QPixmap>
#include <QPainter>
#include <QFileDialog>
void MyImageLabel::updateLabelProperties()
{
setAcceptDrops(type == MyImageLabelType::Input);
}
MyImageLabel::MyImageLabel(QWidget *parent):
QLabel(parent)
{
setMinimumSize(200, 200);
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
setAlignment(Qt::AlignCenter);
updateLabelProperties();
clear();
}
void MyImageLabel::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls())
{
// One file only
auto urlList = event->mimeData()->urls();
if (urlList.size() != 1)
return;
// Only images
auto filePath = urlList[0].toLocalFile();
auto imageFormat = QImageReader::imageFormat(filePath);
if (imageFormat.isNull())
return;
event->acceptProposedAction();
}
}
void MyImageLabel::loadImage(QString filePath)
{
QImageReader imageReader(filePath);
imageReader.read(&originalImage);
updatePixmap();
emit changed();
}
void MyImageLabel::dropEvent(QDropEvent *event)
{
auto filePath = event->mimeData()->urls()[0].toLocalFile();
loadImage(filePath);
}
void MyImageLabel::updatePixmap()
{
if (!originalImage.isNull())
{
auto scaledImage = originalImage.scaled(size(), Qt::KeepAspectRatio);
auto pixmap = QPixmap::fromImage(scaledImage);
setPixmap(pixmap);
}
}
void MyImageLabel::resizeEvent(QResizeEvent * /*event*/)
{
updatePixmap();
}
void MyImageLabel::mouseDoubleClickEvent(QMouseEvent *event)
{
if (type == MyImageLabelType::Output)
return;
auto formats = QImageReader::supportedImageFormats();
QStringList fileExtension;
for (auto& format : formats)
{
fileExtension.push_back(QString("*.%1").arg(QString(format.toLower())));
}
auto fileDialogFilter = QString("Image Files (%1)").arg(fileExtension.join(' '));
auto fileName = QFileDialog::getOpenFileName(this, "Open Image", QString(), fileDialogFilter);
if (!fileName.isNull())
loadImage(fileName);
event->accept();
}
void MyImageLabel::clear()
{
setText("Drop image here or double click for file dialog");
}
|
5cc67d3480196e0e7a7e49d456c81656d5f25cb6
|
1a0bb8dc80f1283f552baf436d9a8e722c22a8f1
|
/proj/fpga/ultra96/camera/Vitis-AI/Vitis-AI-Library/xnnpp/include/vitis/ai/nnpp/facequality5pt.hpp
|
3aaa0ae50ca34549cb31fc0760e6aef8f3c474c2
|
[
"Apache-2.0",
"MIT"
] |
permissive
|
embedded-bitai/Mercenary
|
d457dcc2ace4dd4fe4a82489ecd28c61e3b4fe7a
|
7762bad28e4f49b2ad84fb8abbd8056bd01f61d4
|
refs/heads/master
| 2023-01-09T09:24:52.331403
| 2020-11-16T09:22:39
| 2020-11-16T09:22:39
| 297,019,610
| 4
| 9
|
MIT
| 2020-11-16T09:22:40
| 2020-09-20T06:53:53
|
C++
|
UTF-8
|
C++
| false
| false
| 3,440
|
hpp
|
facequality5pt.hpp
|
/*
* Copyright 2019 Xilinx Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <xilinx/ai/proto/dpu_model_param.pb.h>
#include <array>
#include <utility>
#include <xilinx/ai/tensor.hpp>
namespace xilinx {
namespace ai {
/**
* @struct FaceQuality5ptResult
* @brief The struct of result returned by the facequality5pt network.
*/
struct FaceQuality5ptResult {
/// width of a input image
int width;
/// height of a input image
int height;
/// The quality of face, the value range from 0 to 1.
float score;
/// Five key points coordinate, a array of <x,y> has 5 elements , x and y is
/// normalized relative to input image cols and rows, the value range from 0
/// to 1.
std::array<std::pair<float, float>, 5> points;
};
/**
*@brief The post-processing function of the face quality of 5pt network..
*@param input_tensors A vector of all input-tensors in the network.
* Usage: input_tensors[input_tensor_index].
*@param output_tensors A vector of all output-tensors in the network.
*Usage: output_tensors[output_index].
*@param config The dpu model configuration information.
*@return The struct of face quality.
*/
FaceQuality5ptResult face_quality5pt_post_process(
const std::vector<std::vector<xilinx::ai::library::InputTensor>>&
input_tensors,
const std::vector<std::vector<xilinx::ai::library::OutputTensor>>&
output_tensors,
const xilinx::ai::proto::DpuModelParam& config);
/**
*@brief The post-processing function of the face quality of 5pt network..
*@param input_tensors A vector of all input-tensors in the network.
* Usage: input_tensors[input_tensor_index].
*@param output_tensors A vector of all output-tensors in the network.
*Usage: output_tensors[output_index].
*@param config The dpu model configuration information.
*@return The struct of face quality in day mode.
*/
FaceQuality5ptResult face_quality5pt_post_process_day(
const std::vector<std::vector<xilinx::ai::library::InputTensor>>&
input_tensors,
const std::vector<std::vector<xilinx::ai::library::OutputTensor>>&
output_tensors,
const xilinx::ai::proto::DpuModelParam& config);
/**
*@brief The post-processing function of the face quality of 5pt network..
*@param input_tensors A vector of all input-tensors in the network.
* Usage: input_tensors[input_tensor_index].
*@param output_tensors A vector of all output-tensors in the network.
*Usage: output_tensors[output_index].
*@param config The dpu model configuration information.
*@return The struct of face quality in night mode.
*/
FaceQuality5ptResult face_quality5pt_post_process_night(
const std::vector<std::vector<xilinx::ai::library::InputTensor>>&
input_tensors,
const std::vector<std::vector<xilinx::ai::library::OutputTensor>>&
output_tensors,
const xilinx::ai::proto::DpuModelParam& config);
} // namespace ai
} // namespace xilinx
|
cad54973e83ea2244aa1db14303f379e38d7b8cb
|
e5c51ddf7540455aadffe3270a75f5c45419e704
|
/nfaUsingStack.cpp
|
cd5066f9f4f6f61d89a08801ad103c5fc0a93712
|
[] |
no_license
|
sweety-parmar/compilers
|
467f205d2875d69805403ed9af3c6d98c8aae9c5
|
968ab769271661189c11e88a3270ed1303796396
|
refs/heads/master
| 2021-04-28T08:18:42.969192
| 2018-05-03T11:24:14
| 2018-05-03T11:24:14
| 122,245,653
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,673
|
cpp
|
nfaUsingStack.cpp
|
#include<iostream>
#include<string>
#include<stack>
#include<vector>
using namespace std;
string new_reg_exp;
string reg_exp;
int i=0;
int priority(char ch)
{
switch(ch){
case '*': return 3;
case '.': return 2;
case '+': return 1;
default: return 0;
}
}
string convert_to_postfix(string expr)
{
string postfix;
postfix.clear();
char ch;
stack <char> temp;
for(int i=0;i<expr.length();i++)
{
ch=expr[i];
if(ch=='a'||ch=='b')
{
postfix=postfix+ch;
}
else if(ch=='(')
{
temp.push(ch);
}
else if(ch==')')
{
while(temp.top()!='(')
{
postfix+=temp.top();
temp.pop();
}
temp.pop();
}
else if (ch=='*'||ch=='+'||ch=='.')
{
while(!temp.empty()&&priority(temp.top())>priority(ch))
{
postfix+=temp.top();
temp.pop();
}
temp.push(ch);
}
else
{
cout<<"invalid input.";
}
}
while(!temp.empty())
{
postfix+=temp.top();
temp.pop();
}
return postfix;
}
struct edges
{
int src;
int dst;
char ip;
};
class nfa
{
public:
int initial;
int final;
int no_of_edges;
vector <edges> e;
void single_char(char ch)
{
initial=i++;
final=i++;
no_of_edges=1;
e.push_back({initial,final,ch});
//e.dst.push_back(1);
//e.ip.push_back(ch);
// cout<<initial<<"------"<<e[0].ip<<"----"<<final<<endl;
}
};
vector <nfa> st;
nfa Union(nfa n1,nfa n2)
{
nfa n;
n.no_of_edges=n1.no_of_edges+n2.no_of_edges+4;
n.initial=i++;
n.final=i++;
for(int j=0;j<n1.no_of_edges;j++)
{
n.e.push_back({n1.e[j].src,n1.e[j].dst,n1.e[j].ip});
}
for(int j=0;j<n2.no_of_edges;j++)
{
n.e.push_back({n2.e[j].src,n2.e[j].dst,n2.e[j].ip});
}
n.e.push_back({n.initial,n1.initial,'e'});
n.e.push_back({n.initial,n2.initial,'e'});
n.e.push_back({n1.final,n.final,'e'});
n.e.push_back({n2.final,n.final,'e'});
return n;
}
nfa Concat(nfa n1,nfa n2)
{
nfa n;
n.no_of_edges=n1.no_of_edges+n2.no_of_edges+1;
n.initial=n1.initial;
n.final=n2.final;
for(int j=0;j<n1.no_of_edges;j++)
{
n.e.push_back({n1.e[j].src,n1.e[j].dst,n1.e[j].ip});
}
for(int j=0;j<n2.no_of_edges;j++)
{
n.e.push_back({n2.e[j].src,n2.e[j].dst,n2.e[j].ip});
}
n.e.push_back({n1.final,n2.initial,'e'});
return n;
}
nfa Star(nfa n1)
{
nfa n;
n.no_of_edges=n1.no_of_edges+4;
n.initial=i++;
n.final=i++;
for(int j=0;j<n1.no_of_edges;j++)
{
n.e.push_back({n1.e[j].src,n1.e[j].dst,n1.e[j].ip});
}
n.e.push_back({n.initial,n1.initial,'e'});
n.e.push_back({n1.final,n.final,'e'});
n.e.push_back({n.initial,n.final,'e'});
n.e.push_back({n1.final,n1.initial,'e'});
return n;
}
int main()
{
st.clear();
cout<<"Enter regular expression:";
cin>>reg_exp;
new_reg_exp=convert_to_postfix(reg_exp);
cout<<new_reg_exp<<endl;
// nfa n;
// n.single_char(new_reg_exp[0]);
// n.single_char(new_reg_exp[1]);
//s.push(s1);
for(int i =0;i<new_reg_exp.length();i++)
{
switch(new_reg_exp[i])
{
case 'a':
{
nfa n;
n.single_char(new_reg_exp[i]);
st.push_back(n);
break;
}
case 'b':
{
nfa n;
n.single_char(new_reg_exp[i]);
st.push_back(n);
break;
}
case '+':
{
nfa op1,op2,op3;
op2=st.back();
//cout<<op2.initial;
st.pop_back();
op1=st.back();
st.pop_back();
op3=Union(op1,op2);
st.push_back(op3);
break;
}
case '.':
{
nfa op1,op2,op3;
op2=st.back();
//cout<<op2.initial;
st.pop_back();
op1=st.back();
st.pop_back();
op3=Concat(op1,op2);
st.push_back(op3);
break;
}
case '*':
{
nfa op1,op2;
op1=st.back();
st.pop_back();
op2=Star(op1);
st.push_back(op2);
break;
}
}
}
cout<<"\nFinal nfa is:\n";
cout<<"Initial state:"<<st[0].initial<<endl;
cout<<"Final state:"<<st[0].final<<endl;
cout<<"No of edges:"<<st[0].no_of_edges<<endl;
cout<<"------edges-------"<<endl;
for(int j=0;j<st[0].no_of_edges;j++)
{
for(int x=0;x<st[0].no_of_edges;x++)
{
if(st[0].e[x].src==j)
{
cout<<st[0].e[x].src;
cout<<"-----"<<st[0].e[x].ip<<"----";
cout<<st[0].e[x].dst<<endl;
}
}
}
}
|
3918f893596301ad541f67c246a2de146d13490f
|
23760592f24ce639429ccb7354ba37a905adf20b
|
/src/llapdispatcher/IController.h
|
8fa6d93c115a4fec9f55353ab03ae188bb510e66
|
[] |
no_license
|
per1234/Arduino_Lib_LLAPDispatcher
|
08ed24b3ccdf6fe9e4695a52f70018c364aa9a9c
|
5336335bdee9f17207fa666544f40d7b305642d1
|
refs/heads/master
| 2020-03-23T08:00:02.950149
| 2016-03-03T14:02:49
| 2016-03-03T14:02:49
| 141,302,594
| 0
| 0
| null | 2018-07-17T14:38:42
| 2018-07-17T14:38:41
| null |
UTF-8
|
C++
| false
| false
| 1,374
|
h
|
IController.h
|
/* IController interface
* Paul Wightmore 2015
*/
#ifndef _LLAPDISPATCHER_ICONTROLLER_h
#define _LLAPDISPATCHER_ICONTROLLER_h
namespace LLAPDispatcher {
class IEndpoint;
class IController
{
public:
//! Dispatch an incoming message from LLAP
/**
* \return true if the message was successfully dispatched and therefore handled
*/
virtual bool dispatch(const char* message) = 0;
//! Returns the next message to be sent out via LLAP
/**
* Should ideally be polled in a single frame until there are no more pending messages
*
* \param buffer a 12 byte LLAP message buffer
* \return true if there is a payload to be delivered
*/
virtual bool pending(char* messageBuffer) = 0;
//! Add a new endpoint to the dispatcher
/**
* \pre The endpoint does not already exist
*/
virtual void addEndpoint(IEndpoint* endpoint) = 0;
//! Remove an endpoint
virtual void removeEndpoint(const IEndpoint* endpoint) = 0;
//! Broadcast all responding endpoints
/**
* All responding endpoints will be queried and their resultant messages added to the pending queue. \see pending()
*/
virtual void broadcastResponders() = 0;
//! Reset the controller state
/**
* Will clear any pending messages
*/
virtual void reset() = 0;
};
} // namespace LLAPDispatcher
#endif // _LLAPDISPATCHER_ICONTROLLER_h
|
8d828c9032b53d6d104e2ba65799f1c785b8db48
|
efd7adff589e37ca98d2e3eb245aaeb23f64496e
|
/src/plugins/coreplugin/versiondialog.cpp
|
9ece9693f33c9d44881ebc1be45dd30a674c40ac
|
[] |
no_license
|
Andersbakken/CPlusPlus
|
3cf03c28968243587fa1d4661e7e5a388e62eb43
|
400f0b8f19de1c3fc9b794228c7aeec2259fce81
|
refs/heads/master
| 2021-01-10T20:24:54.067140
| 2013-05-28T03:46:50
| 2013-05-28T03:46:50
| 9,491,173
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,387
|
cpp
|
versiondialog.cpp
|
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "versiondialog.h"
#include <app/app_version.h>
#include <coreplugin/coreconstants.h>
#include <utils/qtcassert.h>
#include <QSysInfo>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
using namespace Core;
using namespace Core::Internal;
VersionDialog::VersionDialog(QWidget *parent)
: QDialog(parent)
{
// We need to set the window icon explicitly here since for some reason the
// application icon isn't used when the size of the dialog is fixed (at least not on X11/GNOME)
setWindowIcon(QIcon(QLatin1String(Constants::ICON_QTLOGO_128)));
setWindowTitle(tr("About Qt Creator"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QGridLayout *layout = new QGridLayout(this);
layout->setSizeConstraint(QLayout::SetFixedSize);
QString version = QLatin1String(Constants::IDE_VERSION_LONG);
QString ideVersionDescription;
#ifdef IDE_VERSION_DESCRIPTION
ideVersionDescription = tr("(%1)").arg(QLatin1String(Constants::IDE_VERSION_DESCRIPTION_STR));
#endif
QString ideRev;
#ifdef IDE_REVISION
//: This gets conditionally inserted as argument %8 into the description string.
ideRev = tr("From revision %1<br/>").arg(QString::fromLatin1(Constants::IDE_REVISION_STR).left(10));
#endif
const QString description = tr(
"<h3>Qt Creator %1 %8</h3>"
"Based on Qt %2 (%3 bit)<br/>"
"<br/>"
"Built on %4 at %5<br />"
"<br/>"
"%9"
"<br/>"
"Copyright 2008-%6 %7. All rights reserved.<br/>"
"<br/>"
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A "
"PARTICULAR PURPOSE.<br/>")
.arg(version,
QLatin1String(qVersion()), QString::number(QSysInfo::WordSize),
QLatin1String(__DATE__), QLatin1String(__TIME__), QLatin1String(Constants::IDE_YEAR),
(QLatin1String(Constants::IDE_AUTHOR)), ideVersionDescription,
ideRev);
QLabel *copyRightLabel = new QLabel(description);
copyRightLabel->setWordWrap(true);
copyRightLabel->setOpenExternalLinks(true);
copyRightLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close);
QTC_CHECK(closeButton);
buttonBox->addButton(closeButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::RejectRole | QDialogButtonBox::AcceptRole));
connect(buttonBox , SIGNAL(rejected()), this, SLOT(reject()));
QLabel *logoLabel = new QLabel;
logoLabel->setPixmap(QPixmap(QLatin1String(Constants::ICON_QTLOGO_128)));
layout->addWidget(logoLabel , 0, 0, 1, 1);
layout->addWidget(copyRightLabel, 0, 1, 4, 4);
layout->addWidget(buttonBox, 4, 0, 1, 5);
}
|
70891e6faee93fdcc38668cc20ad7201eb7b373d
|
c41076f8084b8ea0de62d426d06a23cb11960c2f
|
/Source/Rendering/vaCanvasImpl.h
|
5ab77cffdc274203c9d413a055d5e76daf901f9f
|
[
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] |
permissive
|
xiaojun1604/XeGTAO
|
5850c22fae91bb4d1abf1d4b6b0b25e65c8821c8
|
e7698f874e90f2516fca26c696ec3cd2c70e505a
|
refs/heads/master
| 2023-09-03T11:48:06.506886
| 2021-11-09T13:18:27
| 2021-11-09T13:18:27
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 939
|
h
|
vaCanvasImpl.h
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016-2021, Intel Corporation
//
// SPDX-License-Identifier: MIT
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Author(s): Filip Strugar (filip.strugar@intel.com)
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef VA_CANVAS_TYPE
#ifdef VA_CANVAS_IMPL_INCLUDED
#error This file can only be included from one cpp file
#endif
#define VA_CANVAS_IMPL_INCLUDED
// this file should go out completely in the future; calls like these made to API independent module (vaRenderDeviceContext) should be delegated to API dependent (for ex. vaRenderDeviceContextDX11)
// using std::function callbacks instead for clarity
namespace Vanilla
{
}
#endif
|
43685e3c8a22c41f4bfc41cd19823dcef3076a49
|
8cb90d5b749022640608859dc3555f0879bae664
|
/12-b.cpp
|
46ccd3e3ba0fb04896b44372ea4e90a37bf0e727
|
[] |
no_license
|
cynic64/aoc2020
|
79978be43377081a256b8d7d397d1a9bb989f5f7
|
b8f498687bb9627d95c598e2bbf17406f5bce11c
|
refs/heads/main
| 2023-02-08T03:39:13.156163
| 2020-12-23T07:16:32
| 2020-12-23T07:16:32
| 317,446,129
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,356
|
cpp
|
12-b.cpp
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdexcept>
#include <regex>
#include <unordered_map>
#include <cassert>
#include <cmath>
using namespace std;
int main() {
vector<pair<char, int>> lines;
for (string line; getline(cin, line);) {
auto dir = line[0];
auto n = stoi(line.substr(1));
lines.push_back({dir, n});
}
auto x = 0, y = 0, dx = 1, dy = 0;
for (auto [dir, n] : lines) {
if (dir == 'N') y += n;
else if (dir == 'E') x += n;
else if (dir == 'S') y -= n;
else if (dir == 'W') x -= n;
else if (dir == 'F') {
x += n * dx;
y += n * dy;
} else if (dir == 'L') {
for (; n >= 90; n -= 90) {
swap(dx, dy);
dx *= -1;
}
} else if (dir == 'R') {
for (; n >= 90; n -= 90) {
swap(dx, dy);
dy *= -1;
}
}
}
cout << "Part 1: " << abs(x) + abs(y) << endl;
x = 0, y = 0;
auto vx = 10, vy = 1;
for (auto [dir, n] : lines) {
if (dir == 'N') vy += n;
else if (dir == 'E') vx += n;
else if (dir == 'S') vy -= n;
else if (dir == 'W') vx -= n;
else if (dir == 'F') {
x += n * vx;
y += n * vy;
} else if (dir == 'L') {
for (; n >= 90; n -= 90) {
swap(vx, vy);
vx *= -1;
}
} else if (dir == 'R') {
for (; n >= 90; n -= 90) {
swap(vx, vy);
vy *= -1;
}
}
}
cout << "Part 2: " << abs(x) + abs(y) << endl;
}
|
a7a67ead173e8a87725503599270bbaa0d5f31d3
|
a565e2f5034bc660b2e90d8613ffb4d3787cc854
|
/tools/src/run_retrieval_experiments_with_descriptors.cpp
|
cbf877771dbdff1c2f65b754f4b9e240bb694c80
|
[] |
no_license
|
CamilaAlvarez/descriptor-manager
|
15fd094198a4ce5019445f69c0ead32695413c87
|
ed044650d04b10286ddc6b52460be480816773e1
|
refs/heads/master
| 2020-05-24T23:08:40.421114
| 2017-10-20T16:00:51
| 2017-10-20T16:00:51
| 84,889,048
| 0
| 0
| null | 2017-03-22T19:03:32
| 2017-03-14T00:50:51
|
C++
|
UTF-8
|
C++
| false
| false
| 6,151
|
cpp
|
run_retrieval_experiments_with_descriptors.cpp
|
//
// Created by calvarez on 22-03-17.
//
#include <queue>
#include <iostream>
#include <fstream>
#define STRIP_FLAG_HELP 1
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "boost/filesystem.hpp"
#include "descriptor_manager/network_manager.h"
#ifdef _OPENMP
#include <omp.h>
#endif
DEFINE_string(descriptors_file,"", "File that contains previously computed descriptors");
DEFINE_string(queries, "", "Query id list");
DEFINE_string(retrieved_items, "", "Retrieved items id list");
DEFINE_string(output_dir, "", "Directory where experiment results will be saved");
struct min_heap_comparator{
bool operator()(const std::pair<std::string, float> &a,const std::pair<std::string, float> &b){
return a.second > b.second;
}
};
static bool checkValidFlags(){
return FLAGS_queries.size()!=0 && FLAGS_output_dir.size()!=0 && FLAGS_retrieved_items.size()!=0 &&
FLAGS_descriptors_file.size()!=0;
}
static void fillVectorWithFile(const std::string &file, std::vector<std::string> &vector_to_fill){
std::ifstream input_file(file);
std::string line;
while(std::getline(input_file, line)){
vector_to_fill.push_back(line);
}
}
static void writeResult(const std::string &output_file, const std::string &image_name, const std::string &image_class,
std::priority_queue<std::pair<std::string, float>, std::vector<std::pair<std::string, float>>,
min_heap_comparator> results_heap, descriptor::Descriptors& descriptors){
std::ofstream output(output_file);
CHECK(output.is_open()) << "COULDN'T OPEN OUTPUT FILE: "+output_file;
output << image_name << "\t" << image_class << std::endl;
output << results_heap.size() << std::endl;
int rank = 1;
while(!results_heap.empty()){
std::pair<std::string, float> retrieved_item = results_heap.top();
results_heap.pop();
std::string retrieved_item_id = retrieved_item.first;
output << rank << "\t" << retrieved_item_id << "\t" <<
descriptors.getDescriptor(retrieved_item_id).getImageClass()
<< "\t" << retrieved_item.second << std::endl;
rank++;
}
output.close();
}
static float calculateDistance(float *v, float *u, int size){
float result = 0;
int last_group = size-3;//to ensure the last group has four members
float diff_0 = 0, diff_1 = 0, diff_2 = 0, diff_3 = 0;
unsigned int i = 0;
while (i < last_group) {
diff_0 = v[i] - u[i];
diff_1 = v[i + 1] - u[i + 1];
diff_2 = v[i + 2] - u[i + 2];
diff_3 = v[i + 3] - u[i + 3];
result += diff_0 * diff_0 + diff_1 * diff_1 + diff_2 * diff_2 + diff_3 * diff_3;
i += 4;
}
while (i < size) {
diff_0 = v[i] - u[i];
result += diff_0 * diff_0;
i++;
}
return result;
}
int main(int argc, char *argv[]) {
FLAGS_logtostderr = 1;
gflags::SetUsageMessage("command line brew\n"
"usage: run_retrieval_experiments_with_descriptors \n"
"--descriptors_file <descriptors file path>\n "
"--queries <queries file>\n "
"--retrieved_items <retrieved items list file>\n "
"--output_dir <output directory>\n ");
::google::InitGoogleLogging(argv[0]);
::gflags::ParseCommandLineFlags(&argc, &argv, true);
if (!checkValidFlags()) {
gflags::ShowUsageWithFlagsRestrict(argv[0], "run_retrieval_experiments_with_descriptors");
return 1;
}
descriptor::Descriptors descriptors;
descriptors.loadDescriptorsFromFile(FLAGS_descriptors_file);
boost::filesystem::path output_dir(FLAGS_output_dir);
LOG_IF(WARNING, boost::filesystem::is_directory(output_dir)) << "OUTPUT DIRECTORY EXISTS. FILES MAY BE OVERWRITTEN";
if (!boost::filesystem::is_directory(output_dir)) {
boost::filesystem::create_directory(output_dir);
}
std::vector<std::string> queries;
fillVectorWithFile(FLAGS_queries, queries);
std::vector<std::string> retrieved_items;
fillVectorWithFile(FLAGS_retrieved_items, retrieved_items);
size_t number_queries = queries.size();
#ifdef _OPENMP
omp_lock_t lock;
omp_init_lock(&lock);
#endif
#pragma omp parallel for num_threads(3)
for(int i = 0; i < number_queries ; ++i){
std::priority_queue<std::pair<std::string, float>, std::vector<std::pair<std::string, float>>,
min_heap_comparator> min_heap;
std::string query_name = queries[i];
#ifdef _OPENMP
omp_set_lock(&lock);
#endif
LOG(INFO) << "Experiment for: "+query_name;
#ifdef _OPENMP
omp_unset_lock(&lock);
#endif
descriptor::Descriptor query_descriptor_object = descriptors.getDescriptor(query_name);
int descriptor_size = query_descriptor_object.getDescriptorSize();
float *query_descriptor = query_descriptor_object.getDescriptor();
for (std::vector<std::string>::iterator retrieved_it = retrieved_items.begin();
retrieved_it != retrieved_items.end(); ++retrieved_it) {
std::string retrieved_item = *retrieved_it;
descriptor::Descriptor retrieved_item_descriptor_object = descriptors.getDescriptor(retrieved_item);
float *retrieved_item_descriptor = retrieved_item_descriptor_object.getDescriptor();
//Calculate distance
float distance = calculateDistance(query_descriptor, retrieved_item_descriptor, descriptor_size);
min_heap.push(std::make_pair(retrieved_item, distance));
}
std::string output_file_name = FLAGS_output_dir + "/" + query_name;
writeResult(output_file_name, query_name, query_descriptor_object.getImageClass(), min_heap, descriptors);
#ifdef _OPENMP
omp_set_lock(&lock);
#endif
LOG(INFO) << "Finished experiment for: "+query_name;
#ifdef _OPENMP
omp_unset_lock(&lock);
#endif
}
#ifdef _OPENMP
omp_destroy_lock(&lock);
#endif
descriptors.destroyDescriptors();
return 0;
}
|
758162549fee3f713f0b368ba072f3d8542678b3
|
d9e96244515264268d6078650fa707f34d94ee7a
|
/Utility/TimeUtils.h
|
e04d236f57211b7b136eb2c3e46e25b09310f0b9
|
[
"MIT"
] |
permissive
|
xlgames-inc/XLE
|
45c89537c10561e216367a2e3bcd7d1c92b1b039
|
69cc4f2aa4faf12ed15bb4291c6992c83597899c
|
refs/heads/master
| 2022-06-29T17:16:11.491925
| 2022-05-04T00:29:28
| 2022-05-04T00:29:28
| 29,281,799
| 396
| 102
| null | 2016-01-04T13:35:59
| 2015-01-15T05:07:55
|
C++
|
UTF-8
|
C++
| false
| false
| 567
|
h
|
TimeUtils.h
|
// Copyright 2015 XLGAMES Inc.
//
// Distributed under the MIT License (See
// accompanying file "LICENSE" or the website
// http://www.opensource.org/licenses/mit-license.php)
#pragma once
#include "../Core/Types.h"
namespace Utility
{
typedef uint32 Millisecond; // 1/1000 of a second
typedef uint64 Microsecond; // 1/1000000 of a second
Millisecond Millisecond_Now();
Microsecond Microsecond_Now();
uint64 GetPerformanceCounter();
uint64 GetPerformanceCounterFrequency();
}
using namespace Utility;
|
b376bcaa9f98967e0617f0b59ac8372fc07f98d2
|
5e788cfb678f4afc7c7bbe5761f104172d05869f
|
/EnStarMecro/EnStarMecro/MainScene.h
|
feebf670cf7e5768f0c63d6e5136bf82f9879a28
|
[] |
no_license
|
ounols/Macro-Stars
|
360d99edc19a552cccedca444705fbb5e40af202
|
ff689a410cd1d1e9b85798d58b778a8679d79c00
|
refs/heads/master
| 2023-05-31T09:09:01.782042
| 2018-03-26T16:53:21
| 2018-03-26T16:53:21
| 383,201,232
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 686
|
h
|
MainScene.h
|
#pragma once
#include "Scene.h"
#include <string>
#include <opencv2/core/cuda.inl.hpp>
class MainScene : public Scene {
public:
MainScene();
~MainScene();
bool CheckFirst() override;
bool CheckScene() override;
bool ReadData() override;
void ActionDecision() override;
private:
void ReadPopUp();
void ActionPopUp();
static std::string GetNumber(int x, int y, int width, int height, bool isDilate, bool isErode, int minScalar = 230, int maxScalar = 255, int scale = 2);
static std::string GetNumber(int x, int y, int width, int height);
void AddTodo() const;
private:
bool isPopUp;
bool isHide;
const CvPoint PRODUCE_POS = cvPoint(1340, 700);
CvPoint m_pos;
};
|
de6eb8bfc427e87054d3dae0a04f548783de1328
|
b1bca8a2901f0ae030325c11a891e94e51b76dcb
|
/FootSoldier.hpp
|
b80f94508516ae436de96622ccba6dd0961e5432
|
[] |
no_license
|
Ronmor/WarGame
|
ad6c17b8a95c59722efa5635e38e8069baec7bd3
|
5d6b3a6f3c77f07d23f016d5011d3158b8ecbe67
|
refs/heads/master
| 2022-09-24T21:16:10.762392
| 2020-06-04T10:29:42
| 2020-06-04T10:29:42
| 266,485,121
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 557
|
hpp
|
FootSoldier.hpp
|
#pragma once
#include "Soldier.hpp"
#include <cmath>
namespace WarGame{
class FootSoldier : public WarGame::Soldier
{
protected:
//closest enemy
public:
FootSoldier(uint team_num);
FootSoldier(int life_points,int play_points,uint player_number);
~FootSoldier();
void makeMove2(std::pair<int, int> location);
void makeMove();
virtual void act(Soldier* target);
virtual void heal();
virtual Soldier* calcTarget(std::pair<int, int>&,std::map<Soldier*,std::pair<int, int>>&,std::map<Soldier*,std::pair<int, int>>&);
};
}
|
50df3b68ba0a77300cc1df478d70ab795205b0c4
|
c0f0941e3d6f62dbe6932da3d428ae2afed53b43
|
/offline/packages/trackbase/RawHitSetv1.h
|
091ad88a4fde2ae209a408388a7bc1ce272b7b07
|
[] |
no_license
|
sPHENIX-Collaboration/coresoftware
|
ffbb1bd5c107f45c1b3574996aba6693169281ea
|
19748d09d1997dfc21522e8e3816246691f46512
|
refs/heads/master
| 2023-08-03T15:55:20.018519
| 2023-08-01T23:33:03
| 2023-08-01T23:33:03
| 34,742,432
| 39
| 208
| null | 2023-09-14T20:25:46
| 2015-04-28T16:29:55
|
C++
|
UTF-8
|
C++
| false
| false
| 1,543
|
h
|
RawHitSetv1.h
|
#ifndef TRACKBASE_RAWHITSETV1_H
#define TRACKBASE_RAWHITSETV1_H
/**
* @file trackbase/RawHitSetv1.h
* @author D. McGlinchey, H. PEREIRA DA COSTA
* @date 4 June 2018
* @brief Container for storing RawHit's
*/
#include "TrkrDefs.h"
#include "RawHitSet.h"
#include <iostream>
#include <map>
#include <utility> // for pair
// forward declaration
class RawHit;
class RawHitSetv1 : public RawHitSet
{
public:
RawHitSetv1() = default;
~RawHitSetv1() override
{
RawHitSetv1::Reset();
}
void identify(std::ostream& os = std::cout) const override;
void Reset() override;
void setHitSetKey(const TrkrDefs::hitsetkey key) override
{
m_hitSetKey = key;
}
TrkrDefs::hitsetkey getHitSetKey() const override
{
return m_hitSetKey;
}
void addHit(RawHit*) override;
// void addTpcHit(unsigned short phibin, RawHit*) override;
void setTpcPhiBins(unsigned short phibins) override;
// void removeHit(TrkrDefs::hitkey) override;
// RawHit* getHit(const TrkrDefs::hitkey) const override;
ConstRange getHits() const override;
// ConstRange getTpcHits(unsigned short phibin) const override;
unsigned int size() const override
{
return m_hits.size();
}
unsigned int tpcphibins() const override
{
return m_tpchits.size();
}
VectorTpc2D m_tpchits;
private:
/// unique key for this object
TrkrDefs::hitsetkey m_hitSetKey = TrkrDefs::HITSETKEYMAX;
/// storage for RawHit objects
Vector m_hits;
ClassDefOverride(RawHitSetv1, 1);
};
#endif //TRACKBASE_RawHitSetv1_H
|
ef12d154ecc4b3ad907ffd5d596b435f6b8dac8d
|
300d1ab33d98f74fc2269d07f3753d54790c6755
|
/Examples/GridTools/slice_func.cpp
|
a7451d93578ef47c7c1b93e01ce5b1404c9a13ab
|
[
"BSD-3-Clause"
] |
permissive
|
phymucs/INMOST
|
6c7ec645b6402ec5e5777ff20eaa0769ff17153e
|
c0c6ae1595a86dd0ad69dc2aa262170b605a9b98
|
refs/heads/master
| 2022-04-10T00:18:16.149689
| 2020-03-11T07:10:15
| 2020-03-11T07:10:15
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 41,357
|
cpp
|
slice_func.cpp
|
#include "inmost.h"
#include "slice_func.h"
using namespace INMOST;
double Slice::Search(double r0, double r1, double c0[3], double c1[3], double p[3], bool binary) const
{
double rp = 1.0e20, rp_min = 1.0e20, p_min[3];
int iters = 0;
do
{
double m1 = r0/(r0-r1), m0;
if( m1 < 0.0 || m1 > 1.0 || binary ) m1 = 0.5;
m0 = 1.0-m1;
p[0] = m1*c1[0] + m0*c0[0];
p[1] = m1*c1[1] + m0*c0[1];
p[2] = m1*c1[2] + m0*c0[2];
rp = LevelFunction(p);
if( rp_min > rp )
{
p_min[0] = p[0];
p_min[1] = p[1];
p_min[2] = p[2];
rp_min = rp;
}
if( rp*r0 < 0.0 )
{
c1[0] = p[0];
c1[1] = p[1];
c1[2] = p[2];
r1 = rp;
}
else if( rp*r1 < 0.0 )
{
c0[0] = p[0];
c0[1] = p[1];
c0[2] = p[2];
r0 = rp;
}
iters++;
}
while( fabs(rp) > epsf && iters < maxits );
if( rp > rp_min )
{
p[0] = p_min[0];
p[1] = p_min[1];
p[2] = p_min[2];
rp = rp_min;
}
return rp;
}
double Slice::SearchZero(double r0, double r1, double c0[3], double c1[3], double p[3]) const
{
int iters = 0;
double rp = 1.0e+20;
//std::cout << "r0 " << r0 << " r1 " << r1;
do
{
p[0] = 0.5*c1[0] + 0.5*c0[0];
p[1] = 0.5*c1[1] + 0.5*c0[1];
p[2] = 0.5*c1[2] + 0.5*c0[2];
rp = LevelFunction(p);
//std::cout << " rp " << rp;
if( fabs(rp) < epsf )
{
if( fabs(r0) < epsf )
{
c0[0] = p[0];
c0[1] = p[1];
c0[2] = p[2];
r0 = rp;
//std::cout << "<(l)";
}
else
{
c1[0] = p[0];
c1[1] = p[1];
c1[2] = p[2];
r1 = rp;
//std::cout << "<(r)";
}
}
else
{
if( fabs(r0) > epsf )
{
c0[0] = p[0];
c0[1] = p[1];
c0[2] = p[2];
r0 = rp;
//std::cout << ">(l)";
}
else
{
c1[0] = p[0];
c1[1] = p[1];
c1[2] = p[2];
r1 = rp;
//std::cout << ">(r)";
}
}
iters++;
} while( iters < maxits_zero );
//std::cout << std::endl;
return rp;
}
void Slice::SliceMesh(Mesh & m, bool remove_material_zero)
{
//m.SetTopologyCheck(NEED_TEST_CLOSURE|PROHIBIT_MULTILINE|PROHIBIT_MULTIPOLYGON|GRID_CONFORMITY|DEGENERATE_EDGE|DEGENERATE_FACE|DEGENERATE_CELL | FACE_EDGES_ORDER | MARK_ON_ERROR | ADJACENT_DUPLICATE);
//m->RemTopologyCheck(THROW_EXCEPTION);
TagInteger material = m.CreateTag("MATERIAL",DATA_INTEGER,CELL|FACE|EDGE|NODE,NONE,1);
Tag sliced = m.CreateTag("SLICED",DATA_BULK,FACE|EDGE|NODE,FACE|EDGE|NODE,1);
TagReal level = m.CreateTag("level",DATA_REAL,NODE,NONE,1);
MarkerType original = m.CreateMarker();
std::cout << "marker original " << original << std::endl;
#if defined(USE_OMP)
#pragma omp parallel for
#endif
for(int k = 0; k < m.NodeLastLocalID(); ++k) if(m.isValidNode(k))
{
Node it = m.NodeByLocalID(k);
it->SetMarker(original);
material[it] = 3;
level[it] = LevelFunction(it->Coords().data());
}
for(Mesh::iteratorEdge it = m.BeginEdge(); it != m.EndEdge(); ++it) it->SetMarker(original);
MarkerType slice = m.CreateMarker();
std::cout << "marker slice " << slice << std::endl;
MarkerType mrk = m.CreateMarker();
std::cout << "marker mrk " << mrk << std::endl;
int nslice = 0, nmark = 0;
for(Mesh::iteratorEdge it = m.BeginEdge(); it != m.EndEdge(); ++it) if( !it->GetMarker(mrk) )
{
double p[3],pc0[3],pc1[3];
Storage::real_array c0 = it->getBeg()->Coords();
Storage::real_array c1 = it->getEnd()->Coords();
double r0 = LevelFunction(c0.data());
double r1 = LevelFunction(c1.data());
int m0 = material[it->getBeg()];
int m1 = material[it->getEnd()];
//std::cout << "m0 " << m0 << " m1 " << m1;
bool cut = true;
if (m0 == 3)
{
if( fabs(r0) < epsf )
{
m0 = 2;
it->getBeg()->SetMarker(slice);
cut = false;
nmark++;
}
else if ( r0 < -epsf )
m0 = 0;
else
m0 = 1;
}
if (m1 == 3)
{
if( fabs(r1) < epsf )
{
m1 = 2;
it->getEnd()->SetMarker(slice);
cut = false;
nmark++;
}
else if( r1 < -epsf )
m1 = 0;
else
m1 = 1;
}
material[it->getBeg()] = m0;
material[it->getEnd()] = m1;
//std::cout << " e " << it->LocalID() << " r0 " << r0 << " r1 " << r1 << " m0 " << m0 << " m1 " << m1;
if( (cut || ((fabs(r0) < epsf) ^ (fabs(r1) < epsf))) && m0 != m1 )
//if( (r0*r1 < -1.0e-12) || (fabs(r0*r1) < 1.0e-12 && ((fabs(r0) < 1.0e-6) ^ (fabs(r1) < 1.0e-6))) )
{
int alg = -1;
pc0[0] = c0[0], pc0[1] = c0[1], pc0[2] = c0[2];
pc1[0] = c1[0], pc1[1] = c1[1], pc1[2] = c1[2];
if((fabs(r0) < epsf) ^ (fabs(r1) < epsf))
{
SearchZero(r0,r1,pc0,pc1,p);
alg = 1;
}
else
{
double rp = Search(r0,r1,pc0,pc1,p);
alg = 2;
if( fabs(rp) > epsf ) //cannot find intersection
{
rp = Search(r0,r1,pc0,pc1,p,true);
//p[0] = c0[0]*0.5+c1[0]*0.5;
//p[1] = c0[1]*0.5+c1[1]*0.5;
//p[2] = c0[2]*0.5+c1[2]*0.5;
alg = 3;
}
}
//p[0] = (r0*c1[0] - r1*c0[0])/(r0-r1);
//p[1] = (r0*c1[1] - r1*c0[1])/(r0-r1);
//p[2] = (r0*c1[2] - r1*c0[2])/(r0-r1);
//pstd::cout << " p " << p[0] << " " << p[1] << " " << p[2];
//distance to the corners
double l0 = 0, l1 = 0, l;
for(int r = 0; r < 3; ++r)
{
l0 += (p[r]-c0[r])*(p[r]-c0[r]);
l1 += (p[r]-c1[r])*(p[r]-c1[r]);
}
l0 = sqrt(l0);
l1 = sqrt(l1);
l = l0+l1;
//std::cout << " l0 " << l0 << " l1 " << l1;
if( l0 < epsl*l )
{
material[it->getBeg()] = 2;
it->getBeg()->SetMarker(slice);
nmark++;
//std::cout << " left " << func(c0[0],c0[1],c0[2],type) << " alg " << alg;
}
else if( l1 < epsl*l )
{
material[it->getEnd()] = 2;
it->getEnd()->SetMarker(slice);
nmark++;
//std::cout << " right " << func(c1[0],c1[1],c1[2],type) << " alg " << alg;
}
else
{
//std::cout << " new " << func(p[0],p[1],p[2],type) << " alg " << alg;
Node n = m.CreateNode(p);
level[n] = LevelFunction(p);
material[n] = 2;
n.Bulk(sliced) = 1;
n.SetMarker(slice);
bool was_sliced = it->HaveData(sliced) ? true : false;
ElementArray<Edge> ret = Edge::SplitEdge(it->self(),ElementArray<Node>(&m,1,n.GetHandle()),0);
ret.SetMarker(mrk);
if( was_sliced ) for(int q = 0; q < ret.size(); ++q) ret[q]->Bulk(sliced) = 1;
nslice++;
}
}
//std::cout << std::endl;
}
std::cout << "sliced edges: " << nslice << " marked nodes: " << nmark << std::endl;
if( !Element::CheckConnectivity(&m) )
std::cout << "Connectivity is broken" << std::endl;
{
int mat[3] = {0,0,0};
int tot = 0;
for(Mesh::iteratorNode it = m.BeginNode(); it != m.EndNode(); ++it)
{
mat[material[*it]]++;
tot++;
}
std::cout << "node materials, 0: " << mat[0] << " 1: " << mat[1] << " 2: " << mat[2] << std::endl;
}
for(Mesh::iteratorEdge it = m.BeginEdge(); it != m.EndEdge(); ++it)
{
int mat[3] = {0,0,0};
mat[material[it->getBeg()]]++;
mat[material[it->getEnd()]]++;
if( !(mat[0] == 0 || mat[1] == 0) )
{
material[*it] = 2;
std::cout << "oops, materials for edge nodes were not split, 0: " << mat[0] << ", 1: " << mat[1] << ", 2: " << mat[2] << std::endl;
}
else if( mat[0] != 0 ) material[*it] = 0;
else if( mat[1] != 0 ) material[*it] = 1;
else material[*it] = 2;
}
nslice = 0;
MarkerType unique = m.CreateMarker();
std::cout << "marker unique " << unique << std::endl;
for(Mesh::iteratorFace it = m.BeginFace(); it != m.EndFace(); ++it) if( !it->GetMarker(mrk) )
{
ElementArray<Node> nodes = it->getNodes(slice); //those nodes should be ordered so that each pair forms an edge
if( nodes.size() > 1 ) // if there is 1, then only one vertex touches the plane
{
//int nsliced = 0;
//for(int q = 0; q < (int)nodes.size(); ++q) if( !nodes[q].GetMarker(original) ) nsliced++;
//if there is more then two, then original face is non-convex
//if( nsliced && nodes.size() > 2 ) std::cout << "Looks like face " << it->LocalID() << " is nonconvex, there is " << it->nbAdjElements(NODE) << " nodes, out of them " << nsliced << " new cuts on face" << " slice " << slice << " original " << original << std::endl;
//else
if( nodes.size() == 2 )
{
Edge e = m.CreateEdge(nodes).first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
bool was_sliced = it->HaveData(sliced) ? true : false;
ElementArray<Face> ret = Face::SplitFace(it->self(),ElementArray<Edge>(&m,1,e.GetHandle()),0);
ret.SetMarker(mrk);
if( was_sliced ) for(int q = 0; q < ret.size(); ++q) ret[q]->Bulk(sliced) = 1;
nslice++;
}
else if( it->nbAdjElements(NODE,slice) != it->nbAdjElements(NODE) ) //not entire face is sliced
{
//std::cout << "Face " << it->LocalID();
//std::cout << " sliced nodes " << nodes.size() << "/";
nodes = it->getNodes();
//std::cout << nodes.size();// << std::endl;
double c0[3],c1[3],pc0[3],pc1[3],p[3];
it->Centroid(c0);
double r0 = LevelFunction(c0);
int m0,m1;
if( fabs(r0) < epsf ) m0 = 2;
else if( r0 < -epsf ) m0 = 0;
else m0 = 1;
//std::cout << " centernode m " << m0 << " r " << r0;
Node centernode = InvalidNode();
ElementArray<Edge> split_edges(&m);
ElementArray<Node> cutnodes(&m,nodes.size()), edge_nodes(&m,2);
//calculate nodes that cut along the edges connecting centernode
for(int q = 0; q < (int)nodes.size(); ++q) if( !nodes[q].GetMarker(slice) )
{
nodes[q].Centroid(c1);
double r1 = LevelFunction(c1);
m1 = material[nodes[q]];
bool cut = !(m0 == 2 || m1 == 2);
//std::cout << " n" << q << " m " << m1 << " r1 " << r1;
//if( (r0*r1 < -1.0e-12) || (fabs(r0*r1) < 1.0e-12 && ((fabs(r0) < 1.0e-6) ^ (fabs(r1) < 1.0e-6))))
if( (cut || ((fabs(r0) < epsf) ^ (fabs(r1) < epsf))) && m0 != m1 )
{
pc0[0] = c0[0], pc0[1] = c0[1], pc0[2] = c0[2];
pc1[0] = c1[0], pc1[1] = c1[1], pc1[2] = c1[2];
if( ((fabs(r0) < epsf) ^ (fabs(r1) < epsf)) )
SearchZero(r0,r1,pc0,pc1,p);
else
{
double rp = Search(r0,r1,pc0,pc1,p);
if( fabs(rp) > epsf )
{
//std::cout << "inaccurate search " << rp;
rp = Search(r0,r1,pc0,pc1,p,true);
//std::cout << " binary " << rp << std::endl;
//p[0] = c0[0]*0.5+c1[0]*0.5;
//p[1] = c0[1]*0.5+c1[1]*0.5;
//p[2] = c0[2]*0.5+c1[2]*0.5;
}
}
//distance to the center node
double l0 = 0, l1 = 0, l;
for(int r = 0; r < 3; ++r)
{
l0 += (p[r]-c0[r])*(p[r]-c0[r]);
l1 += (p[r]-c1[r])*(p[r]-c1[r]);
}
l0 = sqrt(l0);
l1 = sqrt(l1);
l = l0+l1;
if( l0 < epsl*l ) //edge goes through centernode
{
if( !centernode.isValid() )
{
centernode = m.CreateNode(c0);
level[centernode] = r0;
}
cutnodes[q] = centernode;
//std::cout << " (c) ";
}
else if( l1 > epsl*l )
{
cutnodes[q] = m.CreateNode(p);
level[cutnodes[q]] = LevelFunction(p);
//std::cout << " (n) ";
}
else
{
//std::cout << " (o) ";
material[nodes[q]] = 2;
}
}
else if( m0 == 2 )
{
if( !centernode.isValid() )
{
centernode = m.CreateNode(c0);
level[centernode] = r0;
}
cutnodes[q] = centernode;
//std::cout << " (C) ";
}
}
//std::cout << std::endl;
for(int q = 0; q < (int)cutnodes.size(); ++q) if( cutnodes[q].isValid() )
{
//std::cout << "New cut node " << cutnodes[q].LocalID() << " at " << q << " on line with " << nodes[q].LocalID() << " r=" << func(cutnodes[q].Coords()[0],cutnodes[q].Coords()[1],cutnodes[q].Coords()[2],type) << std::endl;
Node n = cutnodes[q];
material[n] = 2;
n.Bulk(sliced) = 1;
n.SetMarker(slice);
}
//go over triangles and figure out the path of the cut
for(int q = 0; q < (int)nodes.size(); ++q)
{
int i1 = q;
int i2 = (q+1)%nodes.size();
Node n1 = nodes[i1];
Node n2 = nodes[i2];
bool s1 = n1->GetMarker(slice);
bool s2 = n2->GetMarker(slice);
if( s1 && s2 )
{
//cut passing through edge
//skip this
}
else if( s2 )
{
//check cut on oposite edge
if( cutnodes[i1].isValid() )
{
edge_nodes[0] = n2;
edge_nodes[1] = cutnodes[i1];
std::pair<Edge,bool> en = m.CreateEdge(edge_nodes);
//if( en.second )
{
Edge e = en.first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
}
}
}
else if( s1 )
{
//check cut on oposite edge
if( cutnodes[i2].isValid() )
{
edge_nodes[0] = n1;
edge_nodes[1] = cutnodes[i2];
std::pair<Edge,bool> en = m.CreateEdge(edge_nodes);
//if( en.second )
{
Edge e = en.first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
}
}
}
else if( cutnodes[i1].isValid() && cutnodes[i2].isValid() && cutnodes[i1] != cutnodes[i2])
{
edge_nodes[0] = cutnodes[i1];
edge_nodes[1] = cutnodes[i2];
std::pair<Edge,bool> en = m.CreateEdge(edge_nodes);
//if( en.second )
{
Edge e = en.first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
}
}
}
//split face with multiple edges
if( !split_edges.empty() )
{
int k = 0;
for(int q = 0; q < split_edges.size(); ++q)
{
if( !split_edges[q].GetMarker(unique) )
{
split_edges[q].SetMarker(unique);
split_edges[k++] = split_edges[q];
}
}
split_edges.RemMarker(unique);
split_edges.resize(k);
//std::cout << "Split edges " << split_edges.size() << std::endl;
//for(int q = 0; q < (int)split_edges.size(); ++q)
// std::cout << split_edges[q].getBeg().LocalID() << "<->" << split_edges[q].getEnd().LocalID() << std::endl;
bool was_sliced = it->HaveData(sliced) ? true : false;
//std::cout << "Split face " << it->LocalID();
ElementArray<Face> ret = Face::SplitFace(it->self(),split_edges,0);
ret.SetMarker(mrk);
//std::cout << " new faces: " << ret.size() << ":";
for(int q = 0; q < ret.size(); ++q)
{
int mat[3] = {0,0,0};
ElementArray<Edge> fe = ret[q].getEdges();
for( int l = 0; l < fe.size(); ++l) mat[material[fe[l]]]++;
//std::cout << " " << ret[q].LocalID() << "[" << mat[0] << "," << mat[1] << "," << mat[2] << "]";
}
//std::cout << std::endl;
if( was_sliced ) for(int q = 0; q < ret.size(); ++q) ret[q]->Bulk(sliced) = 1;
nslice++;
}
//else std::cout << "No split edges " << std::endl;
}
//else std::cout << "No new edges on face " << it->LocalID() << std::endl;
}
//else std::cout << "Only one adjacent slice node, face " << it->LocalID() << std::endl;
}
m.ReleaseMarker(unique);
std::cout << "release marker unique " << unique << std::endl;
nmark = 0;
for(Mesh::iteratorEdge it = m.BeginEdge(); it != m.EndEdge(); ++it)
if( !it->GetMarker(slice) && it->getBeg()->GetMarker(slice) && it->getEnd()->GetMarker(slice) )
{
if( material[*it] != 2 )
std::cout << "Edge " << it->LocalID() << " supposed to get material 2, but have " << material[*it] << " nodes " << material[it->getBeg()] << " " << material[it->getEnd()] << std::endl;
it->SetMarker(slice);
nmark++;
}
std::cout << "sliced faces: " << nslice << " marked edges: " << nmark << std::endl;
if( !Element::CheckConnectivity(&m) )
std::cout << "Connectivity is broken" << std::endl;
{
int mat[3] = {0,0,0};
int tot = 0;
for(Mesh::iteratorEdge it = m.BeginEdge(); it != m.EndEdge(); ++it)
{
mat[material[*it]]++;
tot++;
}
std::cout << "edge materials, 0: " << mat[0] << " 1: " << mat[1] << " 2: " << mat[2] << std::endl;
}
for(Mesh::iteratorFace it = m.BeginFace(); it != m.EndFace(); ++it)
{
int mat[3] = {0,0,0};
ElementArray<Edge> edges = it->getEdges();
for(int k = 0; k < (int)edges.size(); ++k)
mat[material[edges[k]]]++;
if( !(mat[0] == 0 || mat[1] == 0) )
{
material[*it] = 2;
std::cout << "oops, materials for face " << it->LocalID() << " edges were not split, 0: " << mat[0] << " ,1: " << mat[1] << " ,2: " << mat[2] <<
" slice edges " << it->getEdges(slice).size() << "/" << it->getEdges().size() << " nodes " << it->getNodes(slice).size() << "/" << it->getNodes().size() << " mrk " << (it->GetMarker(mrk) ? "yes":"no") << std::endl;
}
else if( mat[0] != 0 ) material[*it] = 0;
else if( mat[1] != 0 ) material[*it] = 1;
else material[*it] = 2;
}
nslice = 0;
TagInteger indx = m.CreateTag("TEMP_INDX",DATA_INTEGER,NODE|EDGE,NONE,1);
MarkerType visited = m.CreateMarker();
std::cout << "marker visited " << visited << std::endl;
MarkerType cmrk = m.CreateMarker();
std::cout << "marker cmrk " << cmrk << std::endl;
MarkerType isolate = m.CreateMarker();
std::cout << "marker isolate " << isolate << std::endl;
for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it) if( !it->GetMarker(mrk) )
{
ElementArray<Edge> edges = it->getEdges(slice);
if( !edges.empty() ) //these should form a triangle
{
//check edges form a simple loops, each node should be visited twice
ElementArray<Face> split_faces(&m);
std::map<Node,int> visit_count;
for(ElementArray<Edge>::iterator jt = edges.begin(); jt != edges.end(); ++jt)
{
visit_count[jt->getBeg()]++;
visit_count[jt->getEnd()]++;
}
bool simple = true;
for(std::map<Node,int>::iterator jt = visit_count.begin(); jt != visit_count.end(); ++jt)
simple &= (jt->second == 2);
//std::cout << "Cell " << it->LocalID() << " slice edges " << edges.size() << "/" << it->nbAdjElements(EDGE) << " " << (simple?"simple":"complex") << std::endl;
if( simple )
{
//gather loop by loop and create faces
//int loop_cnt = 0;
//order edges
ElementArray<Edge> order_edges(&m);
Node last;
int nvisited = 0;
bool found = false;
for(int k = 0; k < edges.size(); ++k) if( !edges[k]->GetMarker(original) )
{
nvisited++;
last = InvalidNode();
order_edges.push_back(edges[k]);
order_edges.SetMarker(visited);
found = true;
break;
}
if( !found ) continue;
while(nvisited != edges.size() )
{
found = false;
for(int k = 0; k < edges.size(); ++k) if( !edges[k]->GetMarker(visited) )
{
bool match = false;
if( last.isValid() )
{
if( edges[k]->getBeg() == last )
{
match = true;
last = edges[k]->getEnd();
}
else if( edges[k]->getEnd() == last )
{
match = true;
last = edges[k]->getBeg();
}
}
else
{
if( edges[k]->getBeg() == order_edges.back()->getBeg() || edges[k]->getBeg() == order_edges.back()->getEnd() )
{
match = true;
last = edges[k]->getEnd();
}
else if( edges[k]->getEnd() == order_edges.back()->getBeg() || edges[k]->getEnd() == order_edges.back()->getEnd() )
{
match = true;
last = edges[k]->getBeg();
}
}
if( match )
{
nvisited++;
order_edges.push_back(edges[k]);
order_edges.back().SetMarker(visited);
found = true;
}
}
if( !found || nvisited == edges.size() )
{
if( !order_edges.empty() )
{
//std::cout << "New loop " << ++loop_cnt << ": " << order_edges.size() << " total edges " << edges.size() << std::endl;
//for(int k = 0; k < order_edges.size(); ++k)
// std::cout << order_edges[k].getBeg().LocalID() << "<->" << order_edges[k].getEnd().LocalID() << std::endl;
//std::cout << "All:" << std::endl;
//for(int k = 0; k < edges.size(); ++k)
// std::cout << edges[k].getBeg().LocalID() << "<->" << edges[k].getEnd().LocalID() << " " << (edges[k].GetMarker(visited) ? "visited":"") << " " << (edges[k].GetMarker(original) ? "original":"")<< std::endl;
if( order_edges.size() > 2 )
{
std::pair<Face,bool> f = m.CreateFace(order_edges);
material[f.first] = 2;
f.first->Bulk(sliced) = 1;
split_faces.push_back(f.first);
}
order_edges.clear();
found = false;
for(int k = 0; k < edges.size(); ++k) if( !edges[k]->GetMarker(visited) && !edges[k]->GetMarker(original))
{
nvisited++;
last = InvalidNode();
order_edges.push_back(edges[k]);
order_edges.back().SetMarker(visited);
found = true;
break;
}
if( !found ) break;
}
else break;
}
}
//if( !order_edges.empty() ) std::cout << "size: " << order_edges.size() << std::endl;
edges.RemMarker(visited);
}
else
{
//edges do not breakup into simple loops, have to run complicated algorithm
//split into pyramids joining faces
ElementArray<Face> cfaces = it->getFaces();
ElementArray<Edge> cedges = it->getEdges();
ElementArray<Node> cnodes = it->getNodes();
ElementArray<Node> cutnodes(&m,cnodes.size());
ElementArray<Edge> cutedges(&m,cedges.size());
ElementArray<Node> edge_nodes(&m,2);
for(int k = 0; k < (int)cnodes.size(); ++k) indx[cnodes[k]] = k;
for(int k = 0; k < (int)cedges.size(); ++k) indx[cedges[k]] = k;
double c0[3],c1[3],pc0[3],pc1[3],p[3];
it->Centroid(c0);
double r0 = LevelFunction(c0);
int m0,m1;
if( fabs(r0) < epsf ) m0 = 2;
else if( r0 < -epsf ) m0 = 0;
else m0 = 1;
//std::cout << "Number of cut edges: " << edges.size() << std::endl;
//for(std::map<Node,int>::iterator jt = visit_count.begin(); jt != visit_count.end(); ++jt)
//std::cout << "NODE:" << jt->first.LocalID() << " visited " << jt->second << " times" << std::endl;
//std::cout << "Centernode m " << m0 << " r " << r0 << std::endl;
Node centernode = InvalidNode();
//calculate nodes that cut along the edges connecting centernode
for(int q = 0; q < (int)cnodes.size(); ++q)
{
if( !cnodes[q].GetMarker(slice) )
{
cnodes[q].Centroid(c1);
double r1 = LevelFunction(c1);
m1 = material[cnodes[q]];
bool cut = !(m0 == 2 || m1 == 2);
//std::cout << "NODE:" << cnodes[q].LocalID() << " m " << m1 << " r " << r1 << " " << (cnodes[q].GetMarker(slice)?"":"not ") << "sliced" << std::endl;
if( (cut || ((fabs(r0) < epsf) ^ (fabs(r1) < epsf))) && m0 != m1 )
//if( (r0*r1 < -1.0e-12) || (fabs(r0*r1) < 1.0e-12 && ((fabs(r0) < 1.0e-6) ^ (fabs(r1) < 1.0e-6))))
{
pc0[0] = c0[0], pc0[1] = c0[1], pc0[2] = c0[2];
pc1[0] = c1[0], pc1[1] = c1[1], pc1[2] = c1[2];
if((fabs(r0) < epsf) ^ (fabs(r1) < epsf))
SearchZero(r0,r1,pc0,pc1,p);
else
{
double rp = Search(r0,r1,pc0,pc1,p);
if( fabs(rp) > epsf )
{
//std::cout << "inaccurate search " << rp;
rp = Search(r0,r1,pc0,pc1,p,true);
//std::cout << " binary " << rp << std::endl;
//p[0] = c0[0]*0.5+c1[0]*0.5;
//p[1] = c0[1]*0.5+c1[1]*0.5;
//p[2] = c0[2]*0.5+c1[2]*0.5;
}
}
//distance to the center node
double l0 = 0, l1 = 0, l;
for(int r = 0; r < 3; ++r)
{
l0 += (p[r]-c0[r])*(p[r]-c0[r]);
l1 += (p[r]-c1[r])*(p[r]-c1[r]);
}
l0 = sqrt(l0);
l1 = sqrt(l1);
l = l0+l1;
//std::cout << "l0 " << l0 << " l1 " << l1 << std::endl;
if( l0 < epsl*l ) //edge goes through centernode
{
if( !centernode.isValid() )
{
centernode = m.CreateNode(c0);
level[centernode] = r0;
}
cutnodes[q] = centernode;
//std::cout << "selected centernode " << cutnodes[q].LocalID() << std::endl;
}
else if( l1 > epsl*l )
{
cutnodes[q] = m.CreateNode(p);
level[cutnodes[q]] = LevelFunction(p);
//std::cout << "created new node " << cutnodes[q].LocalID() << std::endl;
}
else if( !cnodes[q].GetMarker(slice))
{
material[cnodes[q]] = 2;
cnodes[q].SetMarker(slice);
ElementArray<Edge> nedges = cnodes[q]->getEdges();
for(int r = 0; r < nedges.size();++r)
if( material[nedges[r]->getBeg()] == 2 && material[nedges[r]->getEnd()] == 2)
material[nedges[r]] = 2;
//std::cout << "use old node " << std::endl;
}
}
else if( m0 == 2 )
{
if( !centernode.isValid() )
{
centernode = m.CreateNode(c0);
level[centernode] = r0;
}
cutnodes[q] = centernode;
//std::cout << "selected centernode(2) " << cutnodes[q].LocalID() << std::endl;
}
}
//else cutnodes[q] = cnodes[q];
}
for(int q = 0; q < (int)cutnodes.size(); ++q) if( cutnodes[q].isValid() )
{
//std::cout << "New cut node " << cutnodes[q].LocalID() << " at " << q << " on line with " << cnodes[q].LocalID() << " r=" << LevelFunction(cutnodes[q].Coords().data()) << std::endl;
Node n = cutnodes[q];
material[n] = 2;
n.Bulk(sliced) = 1;
n.SetMarker(slice);
}
for(int q = 0; q < (int)cnodes.size(); ++q) if( cnodes[q].GetMarker(slice) ) cutnodes[q] = cnodes[q];
//now find cutedges
for(int q = 0; q < (int)cedges.size(); ++q )
{
if( !cedges[q].GetMarker(slice ) )
{
Node n1 = cutnodes[indx[cedges[q].getBeg()]];
Node n2 = cutnodes[indx[cedges[q].getEnd()]];
if( n1.isValid() && n2.isValid() && n1 != n2 )
{
edge_nodes[0] = n1;
edge_nodes[1] = n2;
cutedges[q] = m.CreateEdge(edge_nodes).first;
}
}
}
ElementArray<Edge> alledges(&m); //to draw
for(int q = 0; q < (int)cedges.size(); ++q )
{
//std::cout << "Cell edge " << cedges[q].LocalID() << " m " << material[cedges[q]] << " " << (cedges[q].GetMarker(slice) ? "slice":"orig") << " at " << q << " " << cedges[q].getBeg().LocalID() << "<->" << cedges[q].getEnd().LocalID() << " m " << material[cedges[q].getBeg()] << "<->" << material[cedges[q].getEnd()] << std::endl;
alledges.push_back(cedges[q]);
}
for(int q = 0; q < (int)cutedges.size(); ++q) if( cutedges[q].isValid() )
{
//std::cout << "New cut edge " << cutedges[q].LocalID() << " at " << q << " on plane with " << cedges[q].LocalID() << " " << cutedges[q].getBeg().LocalID() << "<->" << cutedges[q].getEnd().LocalID() << " original " << cedges[q].getBeg().LocalID() << "<->" << cedges[q].getEnd().LocalID() << std::endl;
Edge n = cutedges[q];
material[n] = 2;
n.Bulk(sliced) = 1;
n.SetMarker(slice);
alledges.push_back(n);
}
for(int q = 0; q < (int)cedges.size(); ++q) if( cedges[q].GetMarker(slice) ) cutedges[q] = cedges[q];
ElementArray<Edge> split_edges(&m);
//run over pyramids and collect faces, they should be already ordered into loops
//although we still have to check they form closed loop
std::map<Edge,int> vstcnt;
for(int q = 0; q < (int)cfaces.size(); ++q)
{
split_edges.clear();
ElementArray<Edge> fedges = cfaces[q].getEdges();
for(int r = 0; r < (int)fedges.size(); ++r)
{
if( cutedges[indx[fedges[r]]].isValid() )
split_edges.push_back(cutedges[indx[fedges[r]]]);
}
if( split_edges.size() > 2 ) //at least a triangle
{
visit_count.clear();
for(int r = 0; r < (int)split_edges.size(); ++r)
{
visit_count[split_edges[r].getBeg()]++;
visit_count[split_edges[r].getEnd()]++;
}
bool simple = true;
for(std::map<Node,int>::iterator jt = visit_count.begin(); jt != visit_count.end(); ++jt)
simple &= (jt->second == 2);
if( simple )
{
for(int r = 0; r < split_edges.size(); ++r) vstcnt[split_edges[r]]++;
std::pair<Face,bool> f = m.CreateFace(split_edges);
//std::cout << "Created face " << f.first.LocalID() << " with " << split_edges.size() << " edges: ";
//for(int r = 0; r < split_edges.size(); ++r) std::cout << "EDGE:" << split_edges[r].LocalID() << " ";
//std::cout << " original FACE:" << cfaces[q].LocalID() << std::endl;
material[f.first] = 2;
f.first.Bulk(sliced) = 1;
if( f.second ) split_faces.push_back(f.first);
//else std::cout << "already existed" << std::endl;
}
else
{
//std::cout << "Face not created, node visits:";
//for(std::map<Node,int>::iterator jt = visit_count.begin(); jt != visit_count.end(); ++jt)
// std::cout << " NODE:" << jt->first.LocalID() << " " << jt->second;
//std::cout << " edges: ";
//for(int r = 0; r < split_edges.size(); ++r) std::cout << "EDGE:" << split_edges[r].LocalID() << " ";
//std::cout << " original FACE:" << cfaces[q].LocalID() << std::endl;
}
}
else if( !split_edges.empty() )
{
//std::cout << "Face not created, edges:";
//for(int r = 0; r < (int)split_edges.size(); ++r)
// std::cout << " EDGE:" << split_edges[r].LocalID();
//std::cout << " original FACE:" << cfaces[q].LocalID() << std::endl;
}
}
//resulting surface may touch the element with one or more edge
//making it impossible to separate in conformal way
//
// in this case we have to isolate this edge with additional faces
//
// check if the edge is counted twice and appears on original element
visit_count.clear();
cedges.SetMarker(cmrk);
bool isolate_alogirthm = false;
for(std::map<Edge,int>::iterator jt = vstcnt.begin(); jt != vstcnt.end(); ++jt)
if( jt->first.GetMarker(cmrk) && jt->second > 1 )
{
//std::cout << "edge " << jt->first.LocalID() << " m " << material[jt->first] << " " << jt->first.getBeg().LocalID() << "<->" << jt->first.getEnd().LocalID() << " material " << material[jt->first.getBeg()] << "<->" << material[jt->first.getEnd()] << " visit count " << jt->second << std::endl;
isolate_alogirthm = true;
jt->first.SetMarker(isolate);
}
if( isolate_alogirthm )
//if( false )
{
//std::cout << "Isolation algorithm" << std::endl;
//on pyramids, build faces that start from cutedges and end up with edge on original edge
for(int q = 0; q < (int)cfaces.size(); ++q)
{
split_edges.clear();
ElementArray<Edge> fedges = cfaces[q].getEdges();
bool have_isolate = false;
for(int r = 0; r < (int)fedges.size(); ++r) have_isolate |= fedges[r].GetMarker(isolate);
if( have_isolate )
{
for(int r = 0; r < (int)fedges.size(); ++r) if( !fedges[r].GetMarker(isolate) && !fedges[r].GetMarker(slice) && cutedges[indx[fedges[r]]].isValid() )
{
split_edges.clear();
int cnt = 0;
Edge e;
Face f;
int mat = material[fedges[r]];
e = fedges[r];
Node e1n1 = e.getBeg();
Node e1n2 = e.getEnd();
Node e2n1 = cutnodes[indx[e.getBeg()]];
Node e2n2 = cutnodes[indx[e.getEnd()]];
//std::cout << "Cell edge: " << e.LocalID() << " " << e.getBeg().LocalID() << "<->" << e.getEnd().LocalID() << std::endl;
//std::cout << "Cut edge: " << e.LocalID() << " " << cutnodes[indx[e.getBeg()]].LocalID() << "<->" << cutnodes[indx[e.getEnd()]].LocalID() << std::endl;
split_edges.push_back(e);
if( e2n1.isValid() && e2n1 != e1n1 )
{
edge_nodes[0] = e1n1;
edge_nodes[1] = e2n1;
e = m.CreateEdge(edge_nodes).first;
material[e] = mat;
e.Bulk(sliced) = 1;
//std::cout << "New edge: " << e.LocalID() << " " << e.getBeg().LocalID() << "<->" << e.getEnd().LocalID() << std::endl;
split_edges.push_back(e);
cnt++;
alledges.push_back(e);
}
e = cutedges[indx[fedges[r]]];
//std::cout << "Cut edge: " << e.LocalID() << " " << e.getBeg().LocalID() << "<->" << e.getEnd().LocalID() << std::endl;
split_edges.push_back(e);
if( e2n2.isValid() && e2n2 != e1n2 )
{
edge_nodes[0] = e1n2;
edge_nodes[1] = e2n2;
e = m.CreateEdge(edge_nodes).first;
material[e] = mat;
e.Bulk(sliced) = 1;
//std::cout << "New edge: " << e.LocalID() << " " << e.getBeg().LocalID() << "<->" << e.getEnd().LocalID() << std::endl;
split_edges.push_back(e);
cnt++;
alledges.push_back(e);
}
if( cnt )
{
f = m.CreateFace(split_edges).first;
//std::cout << "New face " << f.LocalID();
//std::cout << " [" << Element::GeometricTypeName(f.GetGeometricType()) << "]";
//std::cout << " nodes (";
ElementArray<Node> fnodes = f.getNodes();
//for(int l = 0; l < fnodes.size(); ++l)
// std::cout << fnodes[l].LocalID() << " ";
//std::cout << ") " << std::endl;
material[f] = mat;
f.Bulk(sliced) = 1;
split_faces.push_back(f);
}
}
}
}
cedges.RemMarker(isolate);
}
cedges.RemMarker(cmrk);
for(int q = 0; q < alledges.size(); ++q)
{
Storage::real_array a = alledges[q].getBeg().Coords();
Storage::real_array b = alledges[q].getEnd().Coords();
int aid = alledges[q].getBeg().LocalID();
int bid = alledges[q].getEnd().LocalID();
//std::cout << alledges[q].LocalID() << " ";
//std::cout << "(" << aid << "," << a[0] << "," << a[1] << "," << a[2] << ")";
//std::cout << " <-> ";
//std::cout << "(" << bid << "," << b[0] << "," << b[1] << "," << b[2] << ")";
//std::cout << std::endl;
}
}
if( !split_faces.empty() )
{
int lid = it->LocalID();
ElementArray<Cell> ret = Cell::SplitCell(it->self(),split_faces,0);
//if(!simple )
if( false )
{
std::cout << (simple?"simple":"complex") << " algorithm, split cell " << lid << " with " << split_faces.size() << " faces ";
for(int q = 0; q < (int)split_faces.size(); ++q)
{
std::cout << split_faces[q].LocalID();
std::cout << " [" << Element::GeometricTypeName(split_faces[q].GetGeometricType()) << "]";
std::cout << " nodes (";
ElementArray<Node> fnodes = split_faces[q].getNodes();
for(int l = 0; l < fnodes.size(); ++l)
std::cout << fnodes[l].LocalID() << " ";
std::cout << ") ";
}
std::cout << " result in " << ret.size() << " cells:";
for(int q = 0; q < (int)ret.size(); ++q)
{
std::cout << " " << ret[q].LocalID();
std::cout << " [" << Element::GeometricTypeName(ret[q].GetGeometricType()) << "]";
std::cout << " nodes (";
ElementArray<Node> cnodes = ret[q].getNodes();
for(int l = 0; l < cnodes.size(); ++l)
std::cout << cnodes[l].LocalID() << " ";
std::cout << ") faces (";
ElementArray<Face> cfaces = ret[q].getFaces();
for(int l = 0; l < cfaces.size(); ++l)
{
std::cout << cfaces[l].LocalID() << " [" << Element::GeometricTypeName(cfaces[l].GetGeometricType()) << "] n{";
ElementArray<Node> fcnodes = cfaces[l].getNodes();
for(int r = 0; r < fcnodes.size(); ++r)
std::cout << fcnodes[r].LocalID() << " ";
std::cout << "} ";
}
std::cout << ")";
}
std::cout << std::endl;
}
//if( ret.size() == 1 ) scanf("%*c");
ret.SetMarker(mrk);
nslice++;
if( false )//ret.size() == 1 && !simple )
{
ElementArray<Edge> cedges = ret[0].getEdges();
cedges.SetMarker(cmrk);
std::cout << "Original cut edges: " << std::endl;
for(int k = 0; k < edges.size(); ++k) std::cout << edges[k].LocalID() << " ";
std::cout << std::endl;
std::cout << "Original cell edges: " << std::endl;
for(int k = 0; k < cedges.size(); ++k) std::cout << cedges[k].LocalID() << " ";
std::cout << std::endl;
std::cout << "Cut faces edges: " << std::endl;
std::map<Edge,int> vstcnt;
for(int q = 0; q < split_faces.size(); ++q)
{
ElementArray<Edge> sedges = split_faces[q].getEdges();
std::cout << "Face " << split_faces[q].LocalID() << ":";
for(int r = 0; r < sedges.size(); ++r)
{
vstcnt[sedges[r]]++;
std::cout << " " << sedges[r].LocalID() << "(" << (sedges[r].GetMarker(cmrk)?"s":"i") << ")";
}
std::cout << std::endl;
}
std::cout << "Visit counts:";
for(std::map<Edge,int>::iterator jt = vstcnt.begin(); jt != vstcnt.end(); ++jt)
std::cout << " EDGE:" << jt->first.LocalID() << "(" << (jt->first.GetMarker(cmrk)?"s":"i") << ") " << jt->second;
std::cout <<std::endl;
std::cout << "Cell faces edges: " << std::endl;
ElementArray<Face> cfaces = ret[0].getFaces();
for(int k = 0; k < cfaces.size(); ++k)
{
ElementArray<Edge> sedges = cfaces[k].getEdges();
std::cout << "Face " << cfaces[k].LocalID() << ":";
for(int r = 0; r < sedges.size(); ++r)
{
vstcnt[sedges[r]]++;
std::cout << " " << sedges[r].LocalID() << "(" << (sedges[r].GetMarker(cmrk)?"s":"i") << ")";
}
std::cout << std::endl;
}
std::cout << "Visit counts including cell's faces:";
for(std::map<Edge,int>::iterator jt = vstcnt.begin(); jt != vstcnt.end(); ++jt)
std::cout << " EDGE:" << jt->first.LocalID() << "(" << (jt->first.GetMarker(cmrk)?"s":"i") << ") " << jt->second;
std::cout <<std::endl;
std::cout << "Cell:" << std::endl;
for(int k = 0; k < cedges.size(); ++k)
{
Storage::real_array c1 = cedges[k].getBeg().Coords();
Storage::real_array c2 = cedges[k].getEnd().Coords();
std::cout << "(" << c1[0] << "," << c1[1] << "," << c1[2] << ")<->(" << c2[0] << "," << c2[1] << "," << c2[2] << ")" << std::endl;
}
std::cout << "Faces:" << std::endl;
for(int q = 0; q < split_faces.size(); ++q)
{
ElementArray<Edge> sedges = split_faces[q].getEdges();
for(int r = 0; r < sedges.size(); ++r)
{
Storage::real_array c1 = sedges[r].getBeg().Coords();
Storage::real_array c2 = sedges[r].getEnd().Coords();
std::cout << "(" << c1[0] << "," << c1[1] << "," << c1[2] << ")<->(" << c2[0] << "," << c2[1] << "," << c2[2] << ")" << std::endl;
}
}
cedges.RemMarker(cmrk);
}
}
}
}
m.ReleaseMarker(isolate);
std::cout << "release marker isolate " << isolate << std::endl;
m.ReleaseMarker(cmrk);
std::cout << "release marker cmrk " << cmrk << std::endl;
m.ReleaseMarker(visited);
std::cout << "release marker visited " << visited << std::endl;
m.DeleteTag(indx);
std::cout << "sliced cells: " << nslice << std::endl;
if( !Element::CheckConnectivity(&m) )
std::cout << "Connectivity is broken" << std::endl;
{
int mat[3] = {0,0,0};
int tot = 0;
for(Mesh::iteratorFace it = m.BeginFace(); it != m.EndFace(); ++it)
{
mat[material[*it]]++;
tot++;
}
std::cout << "face materials, 0: " << mat[0] << " 1: " << mat[1] << " 2: " << mat[2] << std::endl;
}
for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it)
{
int mat[3] = {0,0,0};
ElementArray<Face> faces = it->getFaces();
for(int k = 0; k < (int)faces.size(); ++k)
mat[material[faces[k]]]++;
if( !(mat[0] == 0 || mat[1] == 0) )
{
material[*it] = 2;
std::cout << "oops, materials for cell " << it->LocalID() << " faces were not split, 0: " << mat[0] << " ,1: " << mat[1] << " ,2: " << mat[2] << " slice edges " << it->getEdges(slice).size() << std::endl;
}
else if( mat[0] != 0 ) material[*it] = 0;
else if( mat[1] != 0 ) material[*it] = 1;
else
{
//double cnt[3];
//it->Centroid(cnt);
//double v = func(cnt[0],cnt[1],cnt[2],type);
//it->Integer(material) = (v <= 0.0 ? 0 : 1);
material[*it] = 2;
//std::cout << "oops cannot determine material for cell, all faces have type 2, set to " << material[*it] << std::endl;
}
}
{
int mat[3] = {0,0,0};
int tot = 0;
for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it)
{
mat[material[*it]]++;
tot++;
}
std::cout << "cell materials, 0: " << mat[0] << " 1: " << mat[1] << " 2: " << mat[2] << std::endl;
}
if( remove_material_zero )
{
for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it)
if( material[*it] == 0 )//|| it->Integer(collapse) )
it->Delete();
for(ElementType etype = FACE; etype >= NODE; etype = PrevElementType(etype) )
for(Mesh::iteratorElement it = m.BeginElement(etype); it != m.EndElement(); ++it)
if( it->nbAdjElements(CELL) == 0 ) it->Delete();
}
m.ReleaseMarker(slice,NODE|EDGE);
std::cout << "release marker slice " << slice << std::endl;
m.ReleaseMarker(original,NODE|EDGE);
std::cout << "release marker original " << original << std::endl;
m.ReleaseMarker(mrk,EDGE|FACE|NODE|CELL);
std::cout << "release marker mrk " << mrk << std::endl;
// m.DeleteTag(material);
// m.DeleteTag(level);
//m.Save(grid_out);
//return 0;
}
|
c8c9ff5c20351790eab2a1e90ffa8b8c0a8b50e4
|
ffdc77394c5b5532b243cf3c33bd584cbdc65cb7
|
/mindspore/core/ops/lars_v2_update.cc
|
e7fc21b9615e7317a8d450fa4a166498b028804c
|
[
"Apache-2.0",
"LicenseRef-scancode-proprietary-license",
"MPL-1.0",
"OpenSSL",
"LGPL-3.0-only",
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause-Open-MPI",
"MIT",
"MPL-2.0-no-copyleft-exception",
"NTP",
"BSD-3-Clause",
"GPL-1.0-or-later",
"0BSD",
"MPL-2.0",
"LicenseRef-scancode-free-unknown",
"AGPL-3.0-only",
"Libpng",
"MPL-1.1",
"IJG",
"GPL-2.0-only",
"BSL-1.0",
"Zlib",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-python-cwi",
"BSD-2-Clause",
"LicenseRef-scancode-gary-s-brown",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"Python-2.0",
"LicenseRef-scancode-mit-nagy",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference",
"Unlicense"
] |
permissive
|
mindspore-ai/mindspore
|
ca7d5bb51a3451c2705ff2e583a740589d80393b
|
54acb15d435533c815ee1bd9f6dc0b56b4d4cf83
|
refs/heads/master
| 2023-07-29T09:17:11.051569
| 2023-07-17T13:14:15
| 2023-07-17T13:14:15
| 239,714,835
| 4,178
| 768
|
Apache-2.0
| 2023-07-26T22:31:11
| 2020-02-11T08:43:48
|
C++
|
UTF-8
|
C++
| false
| false
| 7,118
|
cc
|
lars_v2_update.cc
|
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ops/lars_v2_update.h"
#include <map>
#include <set>
#include "abstract/abstract_value.h"
#include "abstract/dshape.h"
#include "abstract/ops/op_infer.h"
#include "abstract/ops/primitive_infer_map.h"
#include "abstract/utils.h"
#include "base/base.h"
#include "ir/anf.h"
#include "ir/dtype/number.h"
#include "ir/primitive.h"
#include "mindapi/src/helper.h"
#include "mindspore/core/ops/nn_ops.h"
#include "ops/op_name.h"
#include "ops/primitive_c.h"
#include "utils/check_convert_utils.h"
#include "utils/convert_utils_base.h"
#include "utils/log_adapter.h"
namespace mindspore {
namespace ops {
namespace {
abstract::ShapePtr LARSUpdateInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto op_name = primitive->name();
MS_LOG(INFO) << "For '" << op_name << "', it's now doing infer shape.";
const int64_t input_num = 6;
CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, op_name);
auto weight_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack());
auto gradient_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->GetShapeTrack());
auto norm_weight_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[2]->GetShapeTrack());
auto norm_gradient_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[3]->GetShapeTrack());
auto weight_decay_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[4]->GetShapeTrack());
auto learning_rate_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[5]->GetShapeTrack());
if (weight_shape[kShape].size() != gradient_shape[kShape].size()) {
MS_EXCEPTION(ValueError) << "For '" << op_name
<< "', weight shape size must be equal to gradient shape size, but got "
<< "weight shape size: " << weight_shape[kShape].size()
<< ", gradient shape size: " << gradient_shape[kShape].size() << ".";
}
if (norm_weight_shape[kShape].size() != norm_gradient_shape[kShape].size()) {
MS_EXCEPTION(ValueError) << "For " << op_name
<< "', norm weight shape size must be equal to norm gradient shape size, but got "
<< "norm weight shape size: " << norm_weight_shape[kShape].size()
<< ", norm gradient shape size: " << norm_gradient_shape[kShape].size() << ".";
}
for (size_t index = 0; index < weight_shape[kShape].size(); index++) {
if (weight_shape[kShape][index] != gradient_shape[kShape][index]) {
MS_EXCEPTION(ValueError) << "For '" << op_name << "', the " << index
<< "th dim of weight shape and gradient shape must be equal, but got "
<< "weight shape[" << index << "]: " << weight_shape[kShape][index]
<< ", gradient shape[" << index << "]: " << gradient_shape[kShape][index] << ".";
}
}
for (size_t index = 0; index < norm_weight_shape[kShape].size(); index++) {
if (norm_weight_shape[kShape][index] != norm_gradient_shape[kShape][index]) {
MS_EXCEPTION(ValueError) << "For '" << op_name << "', the " << index
<< "th dim of norm weight shape and norm gradient shape must be equal, but got "
<< "norm weight shape[" << index << "]: " << norm_weight_shape[kShape][index]
<< ", norm gradient shape[" << index << "]: " << norm_gradient_shape[kShape][index]
<< ".";
}
}
auto shp_len = weight_decay_shape[kShape].size();
auto para_name = input_args[4]->ToString();
(void)CheckAndConvertUtils::CheckInteger(para_name, SizeToLong(shp_len), kLessEqual, 1);
if (shp_len == 1) {
(void)CheckAndConvertUtils::CheckInteger(para_name, weight_decay_shape[kShape][0], kEqual, 1);
}
shp_len = learning_rate_shape[kShape].size();
para_name = input_args[5]->ToString();
(void)CheckAndConvertUtils::CheckInteger(para_name, SizeToLong(shp_len), kLessEqual, 1);
if (shp_len == 1) {
(void)CheckAndConvertUtils::CheckInteger(para_name, learning_rate_shape[kShape][0], kEqual, 1);
}
return std::make_shared<abstract::Shape>(weight_shape[kShape]);
}
TypePtr LARSUpdateInferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
const int64_t input_num = 6;
CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name());
std::map<std::string, TypePtr> types;
(void)types.emplace("Weight dtype", input_args[0]->BuildType());
(void)types.emplace("gradient dtype", input_args[1]->BuildType());
(void)types.emplace("norm weight dtype", input_args[2]->BuildType());
(void)types.emplace("norm gradient dtype", input_args[3]->BuildType());
const std::set<TypePtr> valid_types = {kInt16, kInt32, kFloat16, kFloat32};
(void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(types, valid_types, primitive->name(), true);
return types["Weight dtype"];
}
} // namespace
MIND_API_OPERATOR_IMPL(LARSUpdate, BaseOperator);
AbstractBasePtr LARSUpdateInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
auto infer_type = LARSUpdateInferType(primitive, input_args);
auto infer_shape = LARSUpdateInferShape(primitive, input_args);
return abstract::MakeAbstract(infer_shape, infer_type);
}
// AG means auto generated
class MIND_API AGLARSUpdateInfer : public abstract::OpInferBase {
public:
BaseShapePtr InferShape(const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) const override {
return LARSUpdateInferShape(primitive, input_args);
}
TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const override {
return LARSUpdateInferType(primitive, input_args);
}
AbstractBasePtr InferShapeAndType(const abstract::AnalysisEnginePtr &engine, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) const override {
return LARSUpdateInfer(engine, primitive, input_args);
}
};
REGISTER_PRIMITIVE_OP_INFER_IMPL(LARSUpdate, prim::kPrimLARSUpdate, AGLARSUpdateInfer, false);
} // namespace ops
} // namespace mindspore
|
277a0c0c6af019279f828e45d27acc81946b56df
|
009a122deb030cafcfde4ff16428ef67ee206cfb
|
/main.cpp
|
83525be382e7d127e119678f84c1286691ea8632
|
[] |
no_license
|
gerbauz/OwnWindowsProcessExplorer
|
7ae44cd232b2b145537b88907793bc0a81cc3921
|
5cdad721f309ff740f3129bc83527cfe924b9bd5
|
refs/heads/master
| 2020-04-27T14:35:25.137462
| 2019-04-14T14:46:23
| 2019-04-14T14:46:23
| 174,415,100
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 475
|
cpp
|
main.cpp
|
#include "MainWindow.h"
#include "SecurityDialog.h"
//#include "processlistmodel.h"
#include <QApplication>
//#include <QTreeView>
#include <QTextCodec>
#include "ProcessInfoItem.h"
int main(int argc, char *argv[])
{
int id = qRegisterMetaType<std::shared_ptr<ProcessInfoItem>>();
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
|
d20ce983a38a3983541ffd894d2d463520361b95
|
8239562e9d1620ae942db148f7a5775874fa1b55
|
/2136.cpp
|
0fa6fad904366d712017a4174641307193750d97
|
[] |
no_license
|
Higumabear/POJ
|
1510d3dde88c3595d869cbd88fb12e138411c0c2
|
e5d0823f00e5e1a0cc16b8652abb37ea823cb23a
|
refs/heads/master
| 2020-04-01T19:25:04.098270
| 2017-11-22T02:18:56
| 2017-11-22T02:18:56
| 16,761,319
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 970
|
cpp
|
2136.cpp
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
using namespace std;
int out[26];
int num[26];
int main(int argc, char **argv){
string input;
int maxmag = 0;
fill(num, num + 26, 0);
fill(out, out + 26, 0);
for(int i = 0; i < 4; i++){
getline(cin, input);
for(int j = 0; j < (int)input.length(); j++){
if(isalpha(input[j]))
maxmag = max(maxmag, ++num[input[j] - 'A']);
}
}
//各行は何文字目まで出力するか
for(int i = 0; i < maxmag; i++){
for(int j = 0; j < 26; j++){
if(num[j] >= maxmag - i) out[i] = j;
}
}
//実際に出力
for(int i = 0; i < maxmag; i++){
for(int k = 0; k <= out[i]; k++){
if(num[k] >= maxmag - i)
cout << "*";
else
cout << " ";
if(k != out[i]) cout << " ";
}
cout << endl;
}
for(int i = 0; i < 26; i++){
cout << (char)(i + 'A');
if(i != 25) cout << " ";
}
cout << endl;
return 0;
}
|
c92846df1bf272ac5c326cdf29bf3723665da837
|
70c0dffc9c5c366a8b2535980b35c167d33069fb
|
/Include/Vulkan/RenderControl/Pipelines/VKCompositionPipeline.h
|
0fd3097caf2be930ecbcddb1405a641894a9d669
|
[
"MIT"
] |
permissive
|
StavrosBizelis/NetworkDistributedDeferredShading
|
11f59ee394bf842bdba2656142bf0d3404e7337a
|
07c03ce9b13bb5adb164cd4321b2bba284e49b4d
|
refs/heads/master
| 2020-03-19T05:23:00.507948
| 2018-09-20T22:29:35
| 2018-09-20T22:29:35
| 135,925,178
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 863
|
h
|
VKCompositionPipeline.h
|
#pragma once
#include "Vulkan/RenderControl/Pipelines/VKPipeline.h"
class VKCompositionPipeline : public VKPipeline
{
unsigned int m_inSamplersCount;
public :
VKCompositionPipeline(const std::shared_ptr<VulkanLogicalDeviceManager>& a_logicalDevice, VkRenderPass a_renderPass,
const std::vector<VkPipelineShaderStageCreateInfo>& a_shaders, const unsigned int& a_subpassIndex,
const glm::vec2& a_res, const glm::vec4& a_viewportSettings, const unsigned int& a_inSamplersCount );
virtual void Init();
virtual std::vector<SceneGlobalDataType> GetGlobalDataTypes() const {return {GLOBAL_PROJ_VIEW_MATRIX};}
virtual std::vector<size_t> GetObjUboSizes() const{ return {sizeof(VertexObjectMatrices) }; }
virtual std::vector<size_t> GetGlobalUboSize() const{return {sizeof(VertexViewProjMatrices)}; }
};
|
40f1338c865499865b3e133582c00ad256fe3ccd
|
e1e43f3e90aa96d758be7b7a8356413a61a2716f
|
/datacommsserver/esockserver/inc/es_enum_internal.h
|
1e73ec5c27b4dc7dbaf00c63e019089b9cc86408
|
[] |
no_license
|
SymbianSource/oss.FCL.sf.os.commsfw
|
76b450b5f52119f6bf23ae8a5974c9a09018fdfa
|
bc8ac1a6d5273cbfa7852bbb8ce27d6ddc076984
|
refs/heads/master
| 2021-01-18T23:55:06.285537
| 2010-10-03T23:21:43
| 2010-10-03T23:21:43
| 72,773,202
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,849
|
h
|
es_enum_internal.h
|
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
//
/**
@file
*/
#if !defined (__ES_ENUM_INTERNAL_H__)
#define __ES_ENUM_INTERNAL_H__
#include <es_enum.h>
#include <es_enum_partner.h>
class TConnProviderInfo : public TConnArgBase
/**
@internalTechnology
*/
{
public:
inline TConnProviderInfo()
{
iVersion = KConnArgVersion3;
Mem::FillZ(iInfo,sizeof(iInfo));
}
public:
TUint32 iInfo[5];
};
/**
@internalTechnology
*/
typedef TPckgBuf<TInterfaceNotification> TInterfaceNotificationBuf;
/**
@internalComponent
*/
typedef TPckgBuf<TConnectionEnumArg> TConnEnumArgBuf;
/**
@internalComponent
*/
typedef TPckgBuf<TConnectionGetClientInfoArg> TConnGetClientInfoArgBuf;
class TConnectionSocketInfo
/**
@internalComponent
*/
{
public:
inline TConnectionSocketInfo();
public:
TUint iAddressFamily;
TUint iProtocol;
TSockAddr iSourceAddress;
TSockAddr iDestinationAddress;
};
class TConnectionGetSocketInfoArg : public TConnArgBase
/**
for KCoGetConnectionSocketInfo
@internalComponent
*/
{
public:
TConnectionGetSocketInfoArg();
public:
TUint iIndex;
TConnectionSocketInfo iSocketInfo;
};
/**
@internalComponent
*/
typedef TPckgBuf<TConnectionGetSocketInfoArg> TConnGetSocketInfoArgBuf;
/**
This enum is used as an internal extension to TConnInterfaceState
@internalComponent
*/
enum TConnInterfaceStateInternal
{
EInterfaceRestarting = 0x100
};
#include <es_enum_internal.inl>
#endif // __ES_ENUM_INTERNAL_H__
|
63a54d764a130c9d28c74a8d14f9c04da322cbcb
|
39315f77d9b7672ae9d558e7ae36425525741817
|
/jam/syntax_highlight.cpp
|
651f0f38482f13e54737edcd9aaee1e57d8610d8
|
[
"MIT"
] |
permissive
|
janm31415/jam
|
9ee23f60d42dd129d7b57ec40aad43e4026c6ab8
|
4ce9c106a3248f0dbce94ad05cbaa0c38b92ca70
|
refs/heads/master
| 2021-07-20T16:14:21.823028
| 2021-06-19T09:25:08
| 2021-06-19T09:25:08
| 253,088,704
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,907
|
cpp
|
syntax_highlight.cpp
|
#include "syntax_highlight.h"
#include "utils.h"
#include <cassert>
#include <fstream>
#include <json.hpp>
namespace
{
comment_data make_comment_data_for_cpp()
{
comment_data cd;
cd.multiline_begin = "/*";
cd.multiline_end = "*/";
cd.single_line = "//";
return cd;
}
comment_data make_comment_data_for_assembly()
{
comment_data cd;
cd.single_line = ";";
return cd;
}
comment_data make_comment_data_for_scheme()
{
comment_data cd;
cd.multiline_begin = "#|";
cd.multiline_end = "|#";
cd.single_line = ";";
return cd;
}
comment_data make_comment_data_for_python_and_cmake()
{
comment_data cd;
cd.single_line = "#";
return cd;
}
comment_data make_comment_data_for_xml()
{
comment_data cd;
cd.multiline_begin = "<!--";
cd.multiline_end = "-->";
return cd;
}
comment_data make_comment_data_for_forth()
{
comment_data cd;
cd.multiline_begin = "(";
cd.multiline_end = ")";
cd.single_line = "\\\\";
return cd;
}
std::map<std::string, comment_data> build_map_hardcoded()
{
std::map<std::string, comment_data> m;
m["c"] = make_comment_data_for_cpp();
m["cc"] = make_comment_data_for_cpp();
m["cpp"] = make_comment_data_for_cpp();
m["h"] = make_comment_data_for_cpp();
m["hpp"] = make_comment_data_for_cpp();
m["scm"] = make_comment_data_for_scheme();
m["py"] = make_comment_data_for_python_and_cmake();
m["cmake"] = make_comment_data_for_python_and_cmake();
m["cmakelists.txt"] = make_comment_data_for_python_and_cmake();
m["xml"] = make_comment_data_for_xml();
m["html"] = make_comment_data_for_xml();
m["s"] = make_comment_data_for_assembly();
m["asm"] = make_comment_data_for_assembly();
m["4th"] = make_comment_data_for_forth();
return m;
}
std::map<std::string, comment_data> read_map_from_json(const std::string& filename)
{
nlohmann::json j;
std::map<std::string, comment_data> m;
std::ifstream i(filename);
if (i.is_open())
{
try
{
i >> j;
for (auto ext_it = j.begin(); ext_it != j.end(); ++ext_it)
{
auto element = *ext_it;
if (element.is_object())
{
comment_data cd;
for (auto it = element.begin(); it != element.end(); ++it)
{
if (it.key() == "multiline_begin")
{
if (it.value().is_string())
cd.multiline_begin = it.value().get<std::string>();
}
if (it.key() == "multiline_end")
{
if (it.value().is_string())
cd.multiline_end = it.value().get<std::string>();
}
if (it.key() == "singleline")
{
if (it.value().is_string())
cd.single_line = it.value().get<std::string>();
}
}
m[ext_it.key()] = cd;
}
}
}
catch (nlohmann::detail::exception e)
{
m = build_map_hardcoded();
}
i.close();
}
else
m = build_map_hardcoded();
return m;
}
}
syntax_highlighter::syntax_highlighter()
{
extension_to_data = read_map_from_json(get_file_in_executable_path("comments.json"));
}
syntax_highlighter::~syntax_highlighter()
{
}
bool syntax_highlighter::extension_or_filename_has_syntax_highlighter(const std::string& ext_or_filename) const
{
return extension_to_data.find(ext_or_filename) != extension_to_data.end();
}
comment_data syntax_highlighter::get_syntax_highlighter(const std::string& ext_or_filename) const
{
assert(extension_or_filename_has_syntax_highlighter(ext_or_filename));
return extension_to_data.find(ext_or_filename)->second;
}
|
98f1506a065c5343a3ce4d10a672943dd728f61f
|
1c1669e11d3fd70265bf4e509dbc6e5cfa0308c1
|
/src/linux/sockets/SocketFactory.cpp
|
4fe773dd43e12a327df5887b4094dd61ee152c9a
|
[] |
no_license
|
grey-panther/simple-chat
|
2572b23540e076154584d79f46294d3cf08f1b61
|
7b8e3228facc3580d75b97bdca77e01baf24be6d
|
refs/heads/master
| 2021-09-09T04:29:17.833183
| 2018-03-13T21:02:54
| 2018-03-13T21:02:54
| 103,137,524
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 597
|
cpp
|
SocketFactory.cpp
|
#include "sockets/SocketFactory.hpp"
#include "sockets/ServerSocketTCP.hpp"
#include "sockets/ClientSocketTCP.hpp"
namespace sockets
{
namespace factory
{
template<>
IServerSocketTCP* make<IServerSocketTCP>(const ISocketAddress& address)
{
IServerSocketTCP* socket = new ServerSocketTCP;
socket->set_address(address);
return socket;
}
template<>
IClientSocketTCP* make<IClientSocketTCP>(const ISocketAddress& address)
{
return new ClientSocketTCP;
}
// template<>
// IServerSocketTCP* make<IServerSocketTCP>()
// {
// return new ServerSocketTCP;
// }
}
}
|
0153988400200aeca24d4eeb3df2cef716a6002b
|
cb726a324db9a1269c5671ccdbc188d3920547a3
|
/src/Message_connecttable.h
|
d0def86fd7ccd566889bf6bcf58cbbf9fbcd813e
|
[] |
no_license
|
Eddie41/simple-gateway
|
8a61363ae60854ad6fb23384b5ae15bfcdc87f48
|
20a4b54e044ae22d6d7a11a11551279dba187429
|
refs/heads/master
| 2020-04-23T06:53:10.500068
| 2019-02-25T08:53:53
| 2019-02-25T08:53:53
| 170,989,137
| 0
| 0
| null | null | null | null |
GB18030
|
C++
| false
| false
| 574
|
h
|
Message_connecttable.h
|
#ifndef __MESSAGE_CONNECTTABLE_H_20160506__
#define __MESSAGE_CONNECTTABLE_H_20160506__
#include <iostream>
#include <string>
#include <errno.h>
#include "common.h"
#include "Message.h"
#include "HttpClient.h"
using namespace std;
/*
* 处理10003号报文以及对应的20003号报文
* 建立连接
*/
class MsgConnectTable:public Message
{
public:
// 处理请求
virtual int doRequest();
public:
MsgConnectTable(){};
MsgConnectTable(const int &fd, const int &cmd, char *msg, const int &msg_size);
virtual ~MsgConnectTable(){};
};
#endif
|
2081f921abbf9953de587d2e74e14a07d2cb7cd2
|
37e49d9859efeafdef56d9d07f9b8d7c2df062e1
|
/ATmega644_Cpp/DevBoard/01_Demo/i2c.h
|
0abe14d59acb5525b6e1fbc505cc34ac0e732b20
|
[] |
no_license
|
Beszti85/AVR_8BIT
|
e1a6a4883f25c9f3e13f434c1d16cb8dcfde1dc7
|
fba082ffbe15ab241313cd0ec99aff752fb2e05f
|
refs/heads/master
| 2021-12-25T21:37:23.001278
| 2021-11-07T05:34:36
| 2021-11-07T05:34:36
| 189,660,808
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,240
|
h
|
i2c.h
|
/*
* i2c.h
*
* Created: 2019.08.24. 14:41:10
* Author: Besztercei
*/
#ifndef I2C_H_
#define I2C_H_
#include "my_typedef.h"
#define TW_STATUS (TWSR & 0xF8)
class I2CMaster
{
protected:
public:
I2CMaster(uint16_t speed);
uint8_t Start (void);
void Stop(void);
uint8_t Write(uint8_t data);
uint8_t Read(uint8_t ack, uint8_t* data);
};
inline uint8_t I2CMaster::Start(void)
{
TWCR = ((1 << TWINT) | (1 << TWEN) | (1 << TWSTA)); /* Clear IT flag, send start condition */
while (!(TWCR & (1 << TWINT)))
{
;
}
return ((TW_STATUS == 0x08) || (TW_STATUS == 0x10));
}
inline void I2CMaster::Stop(void)
{
TWCR = ((1 << TWINT) | (1 << TWEN) | (1 << TWSTO));
}
inline uint8_t I2CMaster::Write(uint8_t data)
{
TWDR = data;
TWCR = ((1 << TWINT) | (1 << TWEN));
while (!(TWCR & (1 << TWINT)))
{
;
}
return (TW_STATUS != 0x28);
}
inline uint8_t I2CMaster::Read(uint8_t ack, uint8_t* data)
{
if (ack)
{
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
}
else
{
TWCR = (1<<TWINT) | (1<<TWEN);
}
while (!(TWCR & (1 << TWINT)))
{
;
}
*data = TWDR;
return (TW_STATUS != 0x28);
}
#endif /* I2C_H_ */
|
a50d9e2187c716c6d6bb2da3e8dad28986a24e6e
|
7d6c7718cdd99644ce2ff2746e18afbc3f35de7b
|
/TLC5941/tlcrgb.cpp
|
c8cebf7a3ec18d6cf7534db6385e4c9465971769
|
[] |
no_license
|
miguelangelo78/STM32F4xx-TLC5941
|
c192f624a75e8bb3d53030c0bc087c443b858072
|
e60a7c0046b5e9d4a9c78eced172c36849e95fcb
|
refs/heads/master
| 2021-01-10T06:31:11.461950
| 2015-11-24T01:18:19
| 2015-11-24T01:18:19
| 46,372,203
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,961
|
cpp
|
tlcrgb.cpp
|
/*
* tlcrgb.c
*
* Created on: Nov 18, 2015
* Author: Miguel
*/
#include "tlcrgb.h"
TLC5941 TLCRGB::tlc;
void TLCRGB::init(int rgb_index) {
index = rgb_index;
rgb_off = index * 3;
tlc.init();
}
TLCRGB::TLCRGB(int rgb_index) { init(rgb_index); }
TLCRGB::TLCRGB() {}
void TLCRGB::updateColor() {
tlc.setChannel(rgb_off, (uint16_t)rgb.r);
tlc.setChannel(rgb_off + 1, (uint16_t)rgb.g);
tlc.setChannel(rgb_off + 2, (uint16_t)rgb.b);
}
void TLCRGB::updateColor(rgb_t rgb_struct) {
set(rgb_struct);
updateColor();
}
void TLCRGB::updateAll() {
updateColor();
TLC5941::update();
}
void TLCRGB::updateAll(rgb_t rgb_struct) {
updateColor(rgb_struct);
TLC5941::update();
}
void TLCRGB::set(rgb_t rgb_struct) {
rgb.r = rgb_struct.r;
rgb.g = rgb_struct.g;
rgb.b = rgb_struct.b;
}
void TLCRGB::set(uint16_t r, uint16_t g, uint16_t b) {
rgb.r = r;
rgb.g = g;
rgb.b = b;
}
void TLCRGB::setR(uint16_t r) {
rgb.r = r;
}
void TLCRGB::setG(uint16_t g) {
rgb.g = g;
}
void TLCRGB::setB(uint16_t b) {
rgb.b = b;
}
TLC5941 TLCRGB::getTLC5941() {
return tlc;
}
void TLCRGB::led_test() {
#define LED_COUNT 3
TLCRGB leds[LED_COUNT];
#define update_all_leds() for(int i = 0; i < LED_COUNT; i++) leds[i].updateColor();
for(int i = 0; i < LED_COUNT; i++)
leds[i].init(i);
for(;;) {
for(int i=0;i<LED_COUNT;i++) {
switch(rand() % 3) {
case 0:
if(rand()%5 > 1) {
INC(leds[i].rgb.r, rand() % 3, rand()%0xFF+0x7F, 0);
} else {
DEC(leds[i].rgb.r, rand() % 3, rand()%0xFF+0x7F, 0);
}
break;
case 1:
if(rand()%5 > 1) {
INC(leds[i].rgb.g, rand() % 3,rand()%0xFF+0x7F, 0);
} else {
DEC(leds[i].rgb.g, rand() % 3,rand()%0xFF+0x7F, 0);
}
break;
case 2:
if(rand()%5 > 1) {
INC(leds[i].rgb.b, rand() % 3, rand()%0xFF+0x7F, 0);
} else {
DEC(leds[i].rgb.b, rand() % 3, rand()%0xFF+0x7F, 0);
}
break;
}
}
update_all_leds();
TLC5941::update();
}
}
|
cab2d7998bd559f30bd509e0c29e00939a7c31d8
|
11a246743073e9d2cb550f9144f59b95afebf195
|
/kattis/stretchingstreamers.cpp
|
b49e2e8761068126db7150bd9c0a293cecc9705a
|
[] |
no_license
|
ankitpriyarup/online-judge
|
b5b779c26439369cedc05c045af5511cbc3c980f
|
8a00ec141142c129bfa13a68dbf704091eae9588
|
refs/heads/master
| 2020-09-05T02:46:56.377213
| 2019-10-27T20:12:25
| 2019-10-27T20:12:25
| 219,959,932
| 0
| 1
| null | 2019-11-06T09:30:58
| 2019-11-06T09:30:57
| null |
UTF-8
|
C++
| false
| false
| 2,473
|
cpp
|
stretchingstreamers.cpp
|
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int MAXN = 303;
constexpr int MOD = 1e9 + 7;
int n;
int vals[MAXN];
bool adj[MAXN][MAXN];
int sum(int a, int b) {
int c = a + b;
if (c >= MOD)
c -= MOD;
return c;
}
int prod(int a, int b) {
return (1LL * a * b) % MOD;
}
int modpow(int base, int exp) {
int res = 1;
int cur = base;
for (int p = 1; p <= exp; p <<= 1) {
if (exp & p) {
res = prod(res, cur);
}
cur = prod(cur, cur);
}
return res;
}
inline int inv(int x) {
return modpow(x, MOD - 2);
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
inline int inc(int x) {
return x == n - 1 ? 0 : x + 1;
}
int dp[MAXN][MAXN][2];
// if flag, then we can connect to u. Otherwise, we cannot connect directly to u
int solve(int u, int v, bool flag) {
if (u == v)
return 0;
if (inc(u) == v) {
return 1;
}
if (dp[u][v][flag] != -1) {
return dp[u][v][flag];
}
int ret = 0;
for (int k = inc(u); k != v; k = inc(k)) {
if (adj[u][k] and flag) {
ret = sum(ret, prod(solve(u, k, flag), solve(k, v, flag)));
}
if (adj[k][v]) {
ret = sum(ret, prod(solve(u, k, 0), solve(k, v, 1)));
}
}
return dp[u][v][flag] = ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &vals[i]);
}
for (int i = 0; i < n; ++i) {
adj[i][i] = false;
for (int j = i + 1; j < n; ++j) {
adj[i][j] = adj[j][i] = gcd(vals[i], vals[j]) > 1;
}
}
memset(dp, -1, sizeof(dp));
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (!adj[i][j]) continue;
ans = sum(ans, prod(solve(i, j, 1), solve(j, i, 1)));
}
}
ans = prod(ans, inv(n - 1));
printf("%d\n", ans);
return 0;
}
|
8b3967810b41fded36edea58049d46576e88c92b
|
a55e19c18e2c8f192972bd65f1f78d833e848ae9
|
/scara.h
|
905d80ea8df7793f73bd1366ef1e5ac1eba921ff
|
[
"MIT"
] |
permissive
|
nephen/scarysim
|
39f74ab779b9269e87d072d86e268027cd0f89dd
|
1e3b714937244a84e006913ce0ced854610e6a82
|
refs/heads/master
| 2020-03-16T15:17:32.433368
| 2018-05-11T06:12:45
| 2018-05-11T06:12:45
| 132,736,835
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,110
|
h
|
scara.h
|
#ifndef SCARA_H
#define SCARA_H
#include <QObject>
#include <cmath>
#include <vector>
#include "model.h"
enum SteeringMode { SIMPLE, TARGET };
class Scara : public QObject
{
Q_OBJECT
public:
explicit Scara(QObject *parent = 0);
signals:
public slots:
void go(double dt);
void displayPath();
void display();
double getTh1();
double getTh2();
double getX();
double getY();
double getZ();
void setTh1(double th1);
void setTh2(double th2);
void setZ(double z);
void setMode(SteeringMode mode);
void setTarget(double tx, double ty, double tz);
private slots:
void kinPr();
void kinOdwr();
bool calcSpeed(double vx, double vy, double vz);
private:
double th1, th2, z;
double dth1, dth2, dz;
double posx, posy, posz;
double tx, ty, tz;
SteeringMode mode;
double r1, r2;
Model baseModel, arm1Model, arm2Model, arm3Model;
struct PathPoint { double x, y, z; };
std::vector<PathPoint> path;
};
extern Scara *robot;
#endif // SCARA_H
|
aac5e9b795f93781cc05e4ceda855daeaf29ffdb
|
2347e342d32b7ad50a27c91d43630cc928234363
|
/core/platform.h
|
7773ac8f45fb1149cf65b9111d89bd7ab318beb7
|
[
"MIT"
] |
permissive
|
humkyung/app.framework
|
112ea8269971b990ec0c5a26fca1d14525635d6f
|
6a709c0ccc6a78e66ad8638b2db9d560da5ee77a
|
refs/heads/master
| 2021-01-20T18:33:23.668384
| 2017-04-04T20:23:57
| 2017-04-04T20:23:57
| 63,311,572
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,916
|
h
|
platform.h
|
/* include/geos/platform.h. Generated from platform.h.in by configure. */
#pragma once
#include <assert.h>
/* Set to 1 if you have `int64_t' type */
/* #undef HAVE_INT64_T_64 */
/* Set to 1 if `long int' is 64 bits */
#define HAVE_LONG_INT_64 1
/* Set to 1 if `long long int' is 64 bits */
/* #undef HAVE_LONG_LONG_INT_64 */
/* Set to 1 if you have ieeefp.h */
/* #undef HAVE_IEEEFP_H */
/* Has finite */
#define HAVE_FINITE 1
/* Has isfinite */
#define HAVE_ISFINITE 1
/* Has isnan */
#define HAVE_ISNAN 1
#ifdef HAVE_IEEEFP_H
extern "C"
{
#include <ieeefp.h>
}
#endif
#ifdef HAVE_INT64_T_64
extern "C"
{
#include <inttypes.h>
}
#endif
#if defined(__GNUC__) && defined(_WIN32)
/* For MingW the appropriate definitions are included in
math.h and float.h but the definitions in
math.h are only included if __STRICT_ANSI__
is not defined. Since GEOS is compiled with -ansi that
means those definitions are not available. */
#include <float.h>
#elif linux
#if defined(_UNICODE)
#define _T(x) L ##x
typedef wchar_t TCHAR
#else
#define _T(x) x
typedef char TCHAR
#endif
#endif
#include <limits> // for std::numeric_limits
//Defines NaN for intel platforms
#define DoubleNotANumber std::numeric_limits<double>::quiet_NaN()
//Don't forget to define infinities
#define DoubleInfinity std::numeric_limits<double>::infinity()
#define DoubleNegInfinity -std::numeric_limits<double>::infinity()
#define DoubleMax std::numeric_limits<double>::max()
#ifdef HAVE_INT64_T_64
typedef int64_t int64;
#else
# ifdef HAVE_LONG_LONG_INT_64
typedef long long int int64;
# else
typedef long int int64;
# ifndef HAVE_LONG_INT_64
# define INT64_IS_REALLY32 1
# warning "Could not find 64bit integer definition!"
# endif
# endif
#endif
#if defined(HAVE_FINITE) && !defined(HAVE_ISFINITE)
# define FINITE(x) (finite(x))
#else
# if defined(_MSC_VER)
# define FINITE(x) _finite(static_cast<double>(x))
# else
# define FINITE(x) (isfinite(x))
# endif
#endif
#if defined(HAVE_ISNAN)
# define ISNAN(x) (isnan(x))
#else
# if defined(_MSC_VER)
# define ISNAN(x) _isnan(x)
# elif defined(__MINGW32__)
// sandro furieri: sanitizing MinGW32
# define ISNAN(x) (std::isnan(x))
# elif defined(__OSX__) || defined(__APPLE__)
// Hack for OS/X <cmath> incorrectly re-defining isnan() into oblivion.
// It does leave a version in std.
# define ISNAN(x) (std::isnan(x))
# elif defined(__sun) || defined(__sun__)
# include <math.h>
# define ISNAN(x) (::isnan(x))
# endif
#endif
/*
// In rare cases when an absolute "zero" tolerance is
// required, ON_ZERO_TOLERANCE is used to compare
// numbers. This number should be no smaller than
// ON_EPSILON and should be several orders of
// magnitude smaller than ON_SQRT_EPSILON
//
*/
#define ON_ZERO_TOLERANCE 1.0e-12
/************[ Epsilon constants ]*************/
const double Epsilon_High = 1.0E-16;
const double Epsilon_Medium = 1.0E-10;
const double Epsilon_Low = 1.0E-07;
const double EpsilonV = Epsilon_Medium;
#if defined(DBL_EPSILON)
#define ON_EPSILON DBL_EPSILON
#else
#define ON_EPSILON 2.2204460492503131e-16
#endif
template<typename T> T epsilon();
template<> inline double epsilon<double>() { return static_cast<double>(Epsilon_Medium); }
template<typename T>
inline T infinity()
{
return std::numeric_limits<T>::infinity();
}
template<typename T>
inline bool equals(const T& val1, const T& val2, const T& eps = std::numeric_limits<T>::epsilon())
{
T diff = val1 - val2;
assert(((-eps <= diff) && (diff <= eps)) == (abs(diff) <= eps));
return ((-eps <= diff) && (diff <= eps));
}
#ifndef FINITE
#error "Can not compile without finite or isfinite function or macro"
#endif
#ifndef ISNAN
#error "Can not compile without isnan function or macro"
#endif
|
ed7146de9ec86c6015dbd32dfe970628d43d6ff9
|
bac5375ce53392ca698ada1010466d1a63ca831d
|
/src/KeyView/MsgRecord.h
|
b4846e9572cb8d6f482a9eed2fb2891f47ae55cf
|
[
"Apache-2.0"
] |
permissive
|
shuhari/WinTools
|
99bd00454f9f28e070c8bb975df297a1c88fe0fb
|
bb814eca1330c0f510644c71e6c92c17f231f798
|
refs/heads/master
| 2020-12-02T01:01:08.362694
| 2019-09-27T11:37:10
| 2019-09-27T11:37:10
| 143,998,880
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 865
|
h
|
MsgRecord.h
|
#pragma once
#include <vector>
struct MsgRecord {
public:
enum MsgType {
MsgKeyboard = 1,
MsgMouse = 2,
};
enum {
ColumnCount = 80,
RowCount = 20,
OffsetMsg = 0,
OffsetFlags = 20,
OffsetCh = 35,
OffsetCoord = 55,
OffsetScan = 70,
};
MsgType type;
CString name;
CString flags;
CString ch;
CString coord;
CString scan;
MsgRecord();
MsgRecord(const MsgRecord&);
MsgRecord& operator=(const MsgRecord&);
CString toString();
static CString headerText();
static CString separatorText();
static void appendLeftAlignedText(PWSTR dest, PCWSTR str, size_t fieldWidth);
private:
void copyFrom(const MsgRecord& src);
};
class MsgRecordVector : public std::vector<MsgRecord> {
public:
MsgRecordVector();
~MsgRecordVector();
void append(MsgRecord record);
private:
PWSTR appendLine(PWSTR szOffset, const CString& text);
};
|
ff5315d18b6867f376f875ebad9bdc0c323a79de
|
bad5993049b554c68cd0be4ce7f5c87576d006e1
|
/Greg/7-a/7.cpp
|
b6936af2f34de43e28afa5de4e61c06650a032d7
|
[] |
no_license
|
artjomjuferov/university
|
d14fce9f717d6368d1c2a8700a77cb19ababfafc
|
7d872af128f820097de4d8b8f98ef4c4ba4c1c08
|
refs/heads/master
| 2020-12-11T05:38:09.014013
| 2015-05-12T09:24:24
| 2015-05-12T09:24:24
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,659
|
cpp
|
7.cpp
|
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
#define sizeAlph 50
#define sizeN 10000000
void sort(string& x, int count[], int s[])
{
for (int i = 0; i < sizeAlph; i++)
count[i] = 0;
for (int i = 0; i < x.length(); i++)
count[x[i]-int('a')+1]++;
for (int i = 1; i < sizeAlph; i++)
count[i] += count[i - 1];
for (int i = 0; i < x.length(); i++){
count[x[i]-int('a')+1]--;
s[count[x[i]-int('a')+1]] = i;
}
}
int check(int ind, string& x, string& A)
{
int i = 0;
int n = A.size();
int m = x.size();
while(i<m && i+ind<n)
{
if(A[ind+i]>x[i])
return -1;
else if (A[ind+i]<x[i])
return 1;
++i;
}
if(i<m)
return -1;
else
return 0;
}
int searchL(int n, string& x, string& A, int s[])
{
int l=0;
int r=n-1;
while(l+1<r)
{
int ind = (l+r)>>1;
if(check(s[ind],x,A)<=0)
r=ind;
else
l=ind;
}
if(check(s[r],x,A)==0)
return r;
else
return 0;
}
int searchR(int n, string x, string A, int s[])
{
int l=0;
int r=n;
while(l+1<r)
{
int ind=(l+r)>>1;
if(check(s[ind],x,A)<0)
r=ind;
else
l=ind;
}
if(check(s[l],x,A)==0)
return l;
else
return 0;
}
int cc[sizeAlph];
int s1[sizeN], pos[sizeN], flag[sizeN];
int size[sizeN], start[sizeN], s[sizeN];
int main()
{
ifstream in("input.txt");
// ifstream in("14.in");
ofstream out("output.txt");
string x;
in >> x;
string A;
in >> A;
A = A + char(int('a')-1);
int n = A.length();
sort(A, cc, s);
for (int i = 0; i < n; i++)
{
pos[s[i]] = i;
flag[i] = 0;
}
flag[0] = 1;
start[0] = 0;
for (int i = 1; i < n; i++)
{
if (A[s[i]] != A[s[i - 1]])
{
flag[i] = 1;
start[i] = i;
}
else start[i] = start[i - 1];
}
int h = 1;
while (h < n)
{
for (int i = 0; i < n; i++) size[i] = 0;
for (int i = 0; i < n; i++)
{
if (s[i] >= h)
{
int j = s[i] - h;
int k = start[pos[j]];
s1[k + size[k]] = j;
if (size[k]>0)
{
int j1 = s1[k + size[k] - 1];
if (start[i] != start[pos[j1 + h]])
flag[k + size[k]] = 1;
}
size[k]++;
}
if (s[i] + h >= n) s1[i] = s[i];
}
for (int i = 0; i < n; i++)
{
s[i] = s1[i];
pos[s[i]] = i;
if (flag[i]) start[i] = i;
else start[i] = start[i - 1];
}
h *= 2;
}
int tmpL = searchL(n,x,A,s);
int tmpR = searchR(n,x,A, s);
if(tmpL==0)
out << 0;
else
out << tmpR-tmpL+1;
return 0;
}
|
65e932f512ed06b8e100156062e4434c38cc6d8a
|
07f7ef15bd43cd3e991b2cdcb1df919b0bcfaeba
|
/Classes/TagGameScene.cpp
|
0e818b742f4c3f03dc3900902b91fdf69b439b90
|
[] |
no_license
|
srfernandez/tfg
|
a39b7ecddde9a59c6de2d0b1b7b2bb56ac8dac6d
|
e3ad37b86f8e84e00ca8278563629e0e2e8750fe
|
refs/heads/master
| 2021-06-27T22:11:40.757622
| 2017-03-09T12:41:48
| 2017-03-09T12:41:48
| 57,595,410
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 27,356
|
cpp
|
TagGameScene.cpp
|
#include "TagGameScene.h"
#include "MainMenuScene.h"
#include "GameMenu.h"
#include "EndGame.h"
#include "Definitions.h"
#include "json/document.h"
#include "json/filestream.h"
#include "json/stringbuffer.h"
#include "json/prettywriter.h"
USING_NS_CC;
using namespace rapidjson;
Scene* TagGame::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::createWithPhysics();
scene ->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_NONE);
//scene->getPhysicsWorld()->setGravity(Vect(0,0));
//scene->getPhysicsWorld()->setGravity(Vec2(0,-250.0f));
//PhysicsWorld::DEBUGDRAW_NONE
// 'layer' is an autorelease object
auto layer = TagGame::create();
layer->setPhysicsWorld(scene->getPhysicsWorld());
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool TagGame::init()
{
if(!cocos2d::Layer::init()){ return false;}
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
FILE* fileRead = fopen("/data/data/tfg.videojuego.taggame/files/things.json", "r");
FileStream fs(fileRead);
this->saveFile.ParseStream<0>(fs);
_world=saveFile["Partida"]["World"].GetInt();
_difficulty=saveFile["Partida"]["Difficulty"].GetInt();
//if(_world==2){ Director::getInstance()->getRunningScene()->getPhysicsWorld()->setGravity(Vect(0,0));}
_currentHealth=3;
_currentPoints=0;
auxCombo=1;
_toFinish=0;
auxFinish=0;
isHit=true;
_jumpNumber=0;
//_difficulty=UserDefault::getInstance()->getIntegerForKey("difficulty");
_isWon=true;
switch(_world){
case 1:
world1 = new World1( this );
_bg1 = Sprite::create("bgW1.png");
_bg2 = Sprite::create("bgW1.png");
_foreground=Sprite::createWithSpriteFrameName("foreground.png");
_foreground2 = Sprite::createWithSpriteFrameName("foreground.png");
break;
case 2:
world2 = new World2( this);
_bg1 = Sprite::create("bgW2.png");
_bg2 = Sprite::create("bgW2.png");
_foreground=Sprite::createWithSpriteFrameName("foreground2.png");
_foreground2 = Sprite::createWithSpriteFrameName("foreground2.png");
break;
case 3:
world3 = new World3(this);
auto background= Sprite::create("background.png");
background->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
this->addChild(background,1);
_bg1 = Sprite::createWithSpriteFrameName("BG.png");
_bg2 = Sprite::createWithSpriteFrameName("BG.png");
_foreground=Sprite::createWithSpriteFrameName("foreground3.png");
_foreground2 = Sprite::createWithSpriteFrameName("foreground3.png");
break;
}
audio = CocosDenshion::SimpleAudioEngine::getInstance();
audio->playBackgroundMusic("background_music.mp3", true);
_bg1->setAnchorPoint(Vec2(0,0));
_bg1->setPosition(Vec2(0,0));
_bg2->setAnchorPoint(Vec2(0,0));
_bg2->setPosition(Vec2(_bg1->getBoundingBox().size.width -1,0));
// add the sprite as a child to this layer
this->addChild(_bg1, 10);
this->addChild(_bg2, 10);
_foreground->setAnchorPoint(Vec2(0,0));
_foreground->setPosition(Vec2(0,0));
_foreground2->setAnchorPoint(Vec2(0,0));
_foreground2->setPosition(Vec2(_foreground->getBoundingBox().size.width -1,0));
this->addChild(_foreground2,20);
this->addChild(_foreground,20);
auto edgeBody= PhysicsBody::createEdgeBox(_foreground->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT, 3);
edgeBody->setCollisionBitmask(GROUND_COLLISION_BITMASK);
edgeBody->setContactTestBitmask(true);
edgeBody->setDynamic(false);
auto edgeNode= Node::create();
edgeNode->setPosition(Point(visibleSize.width/2 + origin.x, _foreground->getContentSize().height/2));
edgeNode->setPhysicsBody(edgeBody);
this->addChild(edgeNode);
auto edgeBody2= PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
edgeBody2->setCollisionBitmask(EDGE_COLLISION_BITMASK);
edgeBody2->setContactTestBitmask(false);
auto edgeNode2= Node::create();
edgeNode2->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
edgeNode2->setPhysicsBody(edgeBody2);
this->addChild(edgeNode2);
createMenu();
scheduler();
isTouchingGround=true;
auto contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_1(TagGame::onContactBegin, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener,this);
//Swipe listener
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(TagGame::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(TagGame::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(TagGame::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(TagGame::onTouchCancelled, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
isTouchDown = false;
initialTouchPos[0] = 0;
initialTouchPos[1] = 0;
this->scheduleUpdate();
auto listenerKeyboard = EventListenerKeyboard::create();
listenerKeyboard->onKeyReleased = CC_CALLBACK_2(TagGame::onKeyReleased, this);
getEventDispatcher()->addEventListenerWithFixedPriority(listenerKeyboard, 1);
return true;
}
void TagGame::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
if (keyCode==EventKeyboard::KeyCode::KEY_ESCAPE){
audio->pauseBackgroundMusic();
auto menu = MainMenu::createScene();
Director::getInstance()->replaceScene(menu);
}
else
{
audio->pauseBackgroundMusic();
Director::getInstance()->pause();
auto gameMenu = GameMenu::createScene();
Director::getInstance()->pushScene(gameMenu);
}
}
Vector<SpriteFrame *> TagGame::getAnimation(const char *format, int count)
{
auto spritecache = SpriteFrameCache::getInstance();
Vector<SpriteFrame *> animFrames(8);
char str[100];
for(int i = 1; i <= count; i++)
{
sprintf(str, format, i);
animFrames.pushBack(spritecache->getSpriteFrameByName(str));
}
return animFrames;
}
void TagGame::jump(){
isTouchingGround=false;
_jumpNumber=_jumpNumber+1;
/*if(_jumpNumber==1){
auxFinish=auxFinish+1;
protag->stopAllActions();
protag->runAction(RepeatForever::create(Animate::create(animationArray[1])));
}
auto jumping=cocos2d::JumpBy::create(1.3,Vec2(0,0),300,1);
protag->runAction(jumping);
//auto jumping= MoveBy::create(0.5, Point(0,visibleSize.height/3));
*/
if(world1 != NULL){
auxFinish= world1->Jump(_jumpNumber,auxFinish);
}
else{
auxFinish= world3->Jump(_jumpNumber,auxFinish);
}
}
void TagGame::showMenu(Ref* pSender){
//audio->pauseBackgroundMusic();
Director::getInstance()->pause();
auto gameMenu = GameMenu::createScene();
Director::getInstance()->pushScene(gameMenu);
}
void TagGame::createMenu(){
auto pause= Sprite::create("pause.png");
auto menuButton = MenuItemImage::create("pause.png","pause.png", CC_CALLBACK_1(TagGame::showMenu, this));
menuButton->setPosition(
Vec2(
origin.x + visibleSize.width
- menuButton->getContentSize().width / 2,
origin.y + visibleSize.height
- menuButton->getContentSize().height / 2));
auto menu = Menu::create(menuButton, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 10);
_health= cocos2d::Label::createWithTTF("", "fonts/ArcadeClassic.TTF", 200);
//_health->setAnchorPoint(Vec2(0,1));
//_health->setPosition(Vec2(origin.x + _health->getContentSize().width / 2, origin.y + visibleSize.height - _health->getContentSize().height / 2));
_health->setOpacity(0);
_health->setPosition(Vec2(origin.x+visibleSize.width/2, visibleSize.height/2));
this->addChild(_health, 70);
skull= Sprite::create("skull.png");
skull ->setAnchorPoint(Vec2(0.5,0));
skull->setPosition(Vec2(visibleSize.width/2, (visibleSize.height/2) - 150));
skull->setOpacity(0);
this->addChild(skull,85);
_points= cocos2d::Label::createWithTTF("", "fonts/ArcadeClassic.TTF", 100);
_points->setAnchorPoint(Vec2(0,1));
_points->setPosition(Vec2(origin.x + _points->getContentSize().width / 2, origin.y + visibleSize.height - _points->getContentSize().height / 2));
this->addChild(_points, 71);
updateHealth();
updatePoints();
}
void TagGame::scheduler(){
auto obs = _difficulty+2;
this->schedule(schedule_selector(TagGame::spawnObstacles), (OBSTACLE_SPAWN_FREQUENCY/obs)*visibleSize.width/2);
//this->schedule(schedule_selector(TagGame::spawnBonus), (OBSTACLE_SPAWN_FREQUENCY/obs)*visibleSize.height);
this->schedule(schedule_selector(TagGame::ScrollBG), 0.01f);
}
void TagGame::checkFinish(){
if(_difficulty ==0 &&_toFinish==5){
UserDefault::getInstance()->setBoolForKey("Won",_isWon);
UserDefault::getInstance()->setIntegerForKey("points", _currentPoints);
auto GameWon = EndGame::createScene();
Director::getInstance()->replaceScene(GameWon);
}
else if(_difficulty ==1 &&_toFinish==10){
UserDefault::getInstance()->setBoolForKey("Won",_isWon);
UserDefault::getInstance()->setIntegerForKey("points", _currentPoints);
auto GameWon = EndGame::createScene();
Director::getInstance()->replaceScene(GameWon);
}
else if(_difficulty==2 &&_toFinish==15){
UserDefault::getInstance()->setBoolForKey("Won",_isWon);
UserDefault::getInstance()->setIntegerForKey("points", _currentPoints);
auto GameWon = EndGame::createScene();
Director::getInstance()->replaceScene(GameWon);
}
}
void TagGame::updateHealth(){
char lives[50];
sprintf(lives, "Lives %d", _currentHealth);
std::string livesTxt (lives);
_health->setString(livesTxt);
auto fade = FadeIn::create(1);
_health->runAction(fade);
if(_currentHealth==0){
_isWon=false;
UserDefault::getInstance()->setBoolForKey("Won",_isWon);
auto GameOver = EndGame::createScene();
Director::getInstance()->replaceScene(GameOver);
}
}
void TagGame::updatePoints(){
if (isHit == true){
_currentPoints=0;
char points[50];
sprintf(points, "Points %d", _currentPoints);
std::string pointsTxt (points);
_points->setString(pointsTxt);
isHit=false;
}
else{
_currentPoints=_currentPoints+1;
char points[50];
sprintf(points, "Points %d", _currentPoints);
std::string pointsTxt (points);
_points->setString(pointsTxt);
}
}
void TagGame::spawnObstacles(float dt){
//obstacle.spawnObstacles(this);
if(world1!=NULL){
world1->spawnObstacles(this);
}
else if(world2!=NULL){
world2->spawnObstacles(this);
}
else if(world3!=NULL){
world3->spawnObstacles(this);
}
}
void TagGame::spawnObsW2(float dt){
auto random=cocos2d::random(0,1);
auto obstacle = Sprite::create("Obs.png");
auto obsBody = PhysicsBody::createBox(obstacle->getContentSize());
obsBody->setDynamic(false);
obsBody->setCollisionBitmask( OBSTACLE_COLLISION_BITMASK );
obsBody->setContactTestBitmask( true );
obstacle->setPhysicsBody( obsBody );
auto r = cocos2d::random(0,1);
auto Pos = ( r * visibleSize.height ) + ( obstacle->getContentSize( ).height / 2 );
switch(random){
case 0:
obstacle->setPosition(visibleSize.width + obstacle->getContentSize( ).width + origin.x, Pos );
break;
case 1:
obstacle->setPosition(visibleSize.width+obstacle->getContentSize().width+origin.x, Pos - obstacle->getContentSize().height);
break;
}
this->addChild(obstacle,15);
auto obstacleAction = MoveBy::create(OBSTACLE_MOVEMENT_SPEED * visibleSize.height, Point(-visibleSize.width*1.5,0));
obstacle->runAction(obstacleAction);
}
void TagGame::ScrollBG(float dt){
if(world2==NULL){
_bg1->setPosition(Vec2(_bg1->getPosition().x-1, _bg1->getPosition().y));
_bg2->setPosition(Vec2(_bg2->getPosition().x-1, _bg2->getPosition().y));
if(_bg1->getPosition().x < -_bg1->getBoundingBox().size.width){
_bg1->setPosition( Vec2( _bg2->getPosition().x + _bg2->getBoundingBox().size.width, _bg1->getPosition().y));
}
if(_bg2->getPosition().x < -_bg2->getBoundingBox().size.width){
_bg2->setPosition( Vec2( _bg1->getPosition().x + _bg1->getBoundingBox().size.width, _bg2->getPosition().y));
}
_foreground->setPosition(Vec2(_foreground->getPosition().x-1, _foreground->getPosition().y));
_foreground2->setPosition(Vec2(_foreground2->getPosition().x-1, _foreground2->getPosition().y));
if(_foreground->getPosition().x < -_foreground->getBoundingBox().size.width){
_foreground->setPosition( Vec2( _foreground2->getPosition().x + _foreground2->getBoundingBox().size.width, _foreground->getPosition().y));
}
if(_foreground2->getPosition().x < -_foreground2->getBoundingBox().size.width){
_foreground2->setPosition( Vec2( _foreground->getPosition().x + _foreground->getBoundingBox().size.width, _foreground2->getPosition().y));
}
}
}
bool TagGame::onContactBegin(cocos2d::PhysicsContact &contact){
PhysicsBody *a=contact.getShapeA()->getBody();
PhysicsBody *b=contact.getShapeB()->getBody();
//Character touches an obstacle
if(world1!=NULL){
if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && GROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && GROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
//protag->setTouchGround(true);
_jumpNumber=0;
world1->getRunningAnimation();
/*protag->stopAllActions();
protag->runAction(RepeatForever::create(Animate::create(animationArray[0])));*/
checkFinish();
//isTouchingGround=true;
return true;
}
else if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentHealth=_currentHealth-1;
audio->playEffect("effect.wav",false, 1.f, 0.f, 1.f);
updateHealth();
skull->setPosition(world1->getCurrentPos());
auto fade = FadeIn::create(1);
skull->runAction(fade);
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_toFinish= _toFinish+1;
updatePoints();
checkFinish();
return false;
}
else if ((BONUS_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(BONUS_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentPoints= _currentPoints+4;
updatePoints();
return false;
}
else if ((BONUSHEALTH_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(BONUSHEALTH_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentHealth= _currentHealth+1;
updateHealth();
return false;
}
else if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask())){
return true;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && GROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && GROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
}
else if(world2!=NULL){
if ( ( PROTAG_COLLISION_BITMASK == a->getCollisionBitmask( ) && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask() ) || (PROTAG_COLLISION_BITMASK == b->getCollisionBitmask( ) && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask() ) )
{
audio->playEffect("effect.wav",false, 1.f, 0.f, 1.f);
_currentHealth=_currentHealth-1;
updateHealth();
skull->setPosition(world2->getCurrentPos());
auto fade = FadeIn::create(1);
skull->runAction(fade);
return false;
}
else if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && GROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && GROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
audio->playEffect("effect.wav",false, 1.f, 0.f, 1.f);
_currentHealth=_currentHealth-1;
updateHealth();
skull->setPosition(world2->getCurrentPos());
auto fade = FadeIn::create(1);
skull->runAction(fade);
//isTouchingGround=true;
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_toFinish= _toFinish+1;
updatePoints();
checkFinish();
return false;
}
else if ((BONUS_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(BONUS_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentPoints= _currentPoints+4;
updatePoints();
return false;
}
else if ((BONUSHEALTH_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(BONUSHEALTH_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentHealth= _currentHealth+1;
updateHealth();
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && GROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && GROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
}
else if(world3!=NULL){
if ( ( PROTAG_COLLISION_BITMASK == a->getCollisionBitmask( ) && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask() ) || (PROTAG_COLLISION_BITMASK == b->getCollisionBitmask( ) && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask() ) )
{
audio->playEffect("effect.wav",false, 1.f, 0.f, 1.f);
_currentHealth=_currentHealth-1;
updateHealth();
skull->setPosition(world3->getCurrentPos());
auto fade = FadeIn::create(1);
skull->runAction(fade);
return false;
}
else if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && GROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && GROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
//protag->setTouchGround(true);
_jumpNumber=0;
world3->getRunningAnimation();
/*protag->stopAllActions();
protag->runAction(RepeatForever::create(Animate::create(animationArray[0])));*/
auxFinish=_toFinish;
checkFinish();
//isTouchingGround=true;
return true;
}
else if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && HIGHGROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && HIGHGROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
//protag->setTouchGround(true);
_jumpNumber=0;
world3->getRunningAnimation();
world3->setPosCharacter();
/*protag->stopAllActions();
protag->runAction(RepeatForever::create(Animate::create(animationArray[0])));*/
auxFinish=_toFinish;
checkFinish();
//isTouchingGround=true;
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_toFinish= _toFinish+1;
updatePoints();
checkFinish();
return false;
}
else if ((BONUS_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(BONUS_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentPoints= _currentPoints+4;
updatePoints();
return false;
}
else if ((BONUSHEALTH_COLLISION_BITMASK == b->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(BONUSHEALTH_COLLISION_BITMASK == a->getCollisionBitmask() && PROTAG_COLLISION_BITMASK == b->getCollisionBitmask())){
_currentHealth= _currentHealth+1;
updateHealth();
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
else if((PROTAG_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(PROTAG_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask())){
return true;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && GROUND_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && GROUND_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
else if ((CONTROLLER_COLLISION_BITMASK == b->getCollisionBitmask() && EDGE_COLLISION_BITMASK == a->getCollisionBitmask()) ||
(CONTROLLER_COLLISION_BITMASK == a->getCollisionBitmask() && EDGE_COLLISION_BITMASK == b->getCollisionBitmask())){
return false;
}
}
return true;
}
void TagGame::update(float dt)
{
if (!audio->isBackgroundMusicPlaying()){
audio->resumeBackgroundMusic();
}
if(world1!=NULL || world3 != NULL){
if (true == isTouchDown)
{
if (initialTouchPos[0] - currentTouchPos[0] > visibleSize.width * 0.05)
{
CCLOG("SWIPED LEFT");
//auto action=MoveBy::create(1.3,Vec2(-300, 0));
switch(_world){
case 1:
world1->dashLeft();
break;
case 3:
world3->dashLeft();
break;
}
//world1->dashLeft();
auto fadeskull = FadeOut::create(1);
skull->runAction(fadeskull);
Action* action;
auto fade = FadeOut::create(1);
_health->runAction(fade);
/*if(protag->getPosition().x-250 < protag->getContentSize().width/2){
action=MoveTo::create(0.7,Vec2(origin.x + protag->getContentSize().width/2, protag->getPosition().y));
protag->runAction(action);
}
else{
action=MoveTo::create(0.7,Vec2(protag->getPosition().x-250, protag->getPosition().y));
protag->runAction(action);
}
*/
isTouchDown = false;
}
else if (initialTouchPos[0] - currentTouchPos[0] < - visibleSize.width * 0.05)
{
CCLOG("SWIPED RIGHT");
auto fadeskull = FadeOut::create(1);
skull->runAction(fadeskull);
auto fade = FadeOut::create(1);
_health->runAction(fade);
//auto action=MoveBy::create(1.3,Vec2(protag->getPosition().x-300, 0));
//world1->dashRight();
switch(_world){
case 1:
world1->dashRight();
break;
case 3:
world3->dashRight();
break;
}
/*if(protag->getPosition().x+200 > visibleSize.width - protag->getContentSize().width/2){
auto action=MoveTo::create(0.7,Vec2(visibleSize.width - protag->getContentSize().width/2, protag->getPosition().y));
protag->runAction(action);
}
else{
auto action=MoveTo::create(0.7,Vec2(protag->getPosition().x+200, protag->getPosition().y));
protag->runAction(action);
}
*/
isTouchDown = false;
}
else if (initialTouchPos[1] - currentTouchPos[1] > visibleSize.width * 0.05)
{
CCLOG("SWIPED DOWN");
isTouchDown = false;
}
else if (initialTouchPos[1] - currentTouchPos[1] < - visibleSize.width * 0.05 && _jumpNumber <2)
{
CCLOG("SWIPED UP");
isTouchDown = false;
auto fadeskull = FadeOut::create(1);
skull->runAction(fadeskull);
auto fade = FadeOut::create(1);
_health->runAction(fade);
jump();
//protag->isTouchingGround() == true
//protag->Jump();
}
}
}
else if(world2!=NULL){
world2->Fall();
}
}
void TagGame::Float(){
if ( true == isFloating )
{
protag->setPositionX( visibleSize.width / 2 + origin.x );
protag->setPositionY( protag->getPositionY() - ( PROTAG_FALLING_SPEED * visibleSize.height ) );
}
else
{
protag->setPositionX( visibleSize.width / 2 + origin.x );
protag->setPositionY( protag->getPositionY() + ( PROTAG_FALLING_SPEED * visibleSize.height ) );
}
}
void TagGame::stopSwimming(float dt){
world2->stopSwimming();
}
bool TagGame::onTouchBegan(Touch *touch, Event *event)
{
if(world2!=NULL){
auto fade = FadeOut::create(1);
_health->runAction(fade);
auto fadeskull = FadeOut::create(1);
skull->runAction(fadeskull);
world2->swim();
this->scheduleOnce( schedule_selector( TagGame::stopSwimming ), PROTAG_SWIM_DURATION );
}
else{
initialTouchPos[0] = touch->getLocation().x;
initialTouchPos[1] = touch->getLocation().y;
currentTouchPos[0] = touch->getLocation().x;
currentTouchPos[1] = touch->getLocation().y;
isTouchDown = true;
}
return true;
}
void TagGame::onTouchMoved(Touch *touch, Event *event)
{
currentTouchPos[0] = touch->getLocation().x;
currentTouchPos[1] = touch->getLocation().y;
}
void TagGame::onTouchEnded(Touch *touch, Event *event)
{
isTouchDown = false;
}
void TagGame::onTouchCancelled(Touch *touch, Event *event)
{
onTouchEnded(touch, event);
}
void TagGame::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
|
0eb9f39c40840fc8738466a20476acea4ec6d0df
|
267b5ebec0558dc9677404a27c4b7c88fe000a0e
|
/mas programas C/fact.cpp
|
a1e9b09f83476291981dfea8b9034239e58b8724
|
[] |
no_license
|
pixelead0/abandonware_programas_c
|
64e3ecb8bbeef8db2ce0cef28de616bb618e31f1
|
8f7e99dbad8de9cb3802bed1e11c7284b97eeb4a
|
refs/heads/master
| 2022-06-21T04:25:36.447932
| 2020-05-14T05:13:54
| 2020-05-14T05:13:54
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 758
|
cpp
|
fact.cpp
|
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
long int fact,x,i;
textbackground(BLUE);
textcolor(WHITE);
clrscr();
otro:
gotoxy(15,2);
printf("Programa que calcula el factorial de un numero N");
gotoxy(25,12);
cprintf("El numero debe estar entre 1 y 16");
gotoxy(15,10);
printf("Hasta que numero desea que se calcule el facorial: ");
scanf("%ld",&x);
if ((x<=0) || (x>16))
{
sound(300);
delay(200);
nosound();
textcolor(LIGHTGREEN);
gotoxy(25,12);
cprintf("El numero debe estar entre 1 y 16");
goto otro;
}
textcolor(WHITE);
clrscr();
fact=1;
for (i=1; i<=x; i++)
{
fact *=i;
printf("\n %ld! = %ld",i,fact);
}
getch();
}
|
b1ec2a3ba3f62600890c9471d7d4022b5273c480
|
03eb878a99f8f21c72447795297267baed4e0b14
|
/MyIPMsg/app.cpp
|
4e025c6212e4b326b2660693fb4f340307cc2c23
|
[] |
no_license
|
nswdbbnswda/MyIPMsg
|
bb72b5385ab14c47777f4b324b8f861184393da5
|
e49b34289e9ac2f76f26043ebc0f29cde81d1de4
|
refs/heads/master
| 2021-05-10T12:41:04.111126
| 2018-01-31T04:06:08
| 2018-01-31T04:06:08
| 118,448,397
| 0
| 1
| null | null | null | null |
GB18030
|
C++
| false
| false
| 3,250
|
cpp
|
app.cpp
|
#include"app.h"
#include<debugapi.h>
#include"tapi32u8.h"
#include"TMainWin.h"
TApp* TApp::tapp = NULL;
TApp::TApp(HINSTANCE _hI, LPSTR _cmdLine, int _nCmdShow)
{
hI = _hI;
cmdLine = _cmdLine;
nCmdShow = _nCmdShow;
mainWnd = NULL;
preWnd = NULL;
defaultClass = "tapp";
defaultClassW = L"tapp";//宽字符版本
tapp = this;
twinId = 1;
hash = new TWinHashTbl(100);//实例化一个哈希表
}
TApp::~TApp()
{
delete mainWnd;
if (hash) delete hash;
}
BOOL TApp::InitApp(void)
{
WNDCLASSW wc;//创建飞鸽的主窗口类
wc.style = CS_HREDRAW | CS_VREDRAW; //设置窗口风格
wc.lpfnWndProc = WinProc;//这个就是创建飞鸽传书主窗口的函数,并设置主窗口的消息响应函数为TApp:WinProc
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;//程序的实例句柄
wc.hIcon = LoadIcon(TApp::GetInstance(),(LPCSTR)IDI_ICON1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);//加载鼠标资源
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//设置窗口的背景颜色
wc.lpszMenuName = NULL;//不设置菜单
wc.lpszClassName = defaultClassW;
if (::FindWindowW(defaultClassW, NULL) == NULL)
{
if (::RegisterClassW(&wc) == 0)//注册窗口类
return FALSE;
}
return TRUE;
}
int TApp::Run()
{
MSG msg;//创建消息结构
InitApp();//创建窗口类以及注册窗口类
InitWindow();//初始化窗体
while (::GetMessage(&msg, NULL, 0, 0))
{
//if (PreProcMsg(&msg))
// continue;
::TranslateMessage(&msg);//翻译消息
::DispatchMessage(&msg);//转发消息
}
return (int)msg.wParam;
}
//翻译窗口消息以及确认是否是对话框消息
BOOL TApp::PreProcMsg(MSG * msg)
{
//for (HWND hWnd = msg->hwnd; hWnd; hWnd = ::GetParent(hWnd))
//{
// TWin *win = SearchWnd(hWnd);//从哈希表中找到这个窗口句柄
// if (win)
// return win->PreProcMsg(msg);
//}
return FALSE;
}
//窗口消息处理函数
LRESULT CALLBACK TApp::WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TApp *app = TApp::GetApp();
TWin *win = app->SearchWnd(hWnd); //Search方法是从wndArray中找到中找到窗口句柄为hWnd的TWin对象返回
if (win)//找到TMainWin的对象win,调用win->WinProc(uMsg, wParam, lParam)。
return win->WinProc(uMsg, wParam, lParam);//在第一次调用CreateWindowEx函数返回之前先会触发一条WM_CREATE消息,这里要把该消息转发给WinPro
if ((win = app->preWnd))//第一次调用CreateWindowEx时,在函数返回窗口句柄前,会触发WM_CREATE消息,这里是对该消息进行特殊处理
{
app->preWnd = NULL;
app->AddWinByWnd(win, hWnd);//在这里把第一个窗口对象加入到哈希表中
return win->WinProc(uMsg, wParam, lParam);
}
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
//*********************************************APP子类******************************************************************/
TMsgApp::TMsgApp(HINSTANCE _hI, LPSTR _cmdLine, int _nCmdShow) : TApp(_hI, _cmdLine, _nCmdShow)
{
LoadLibrary("RICHED20.DLL");
//srand((UINT)Time());//提供随机种子
}
TMsgApp::~TMsgApp()
{
}
//在这里创建各种窗口
void TMsgApp::InitWindow(void)
{
mainWnd = new TMainWin;
mainWnd->CreateU8(this->defaultClass);
}
|
fe8e2028d6a40aaa6a0b3960da256c75d73eb9d4
|
cfeac52f970e8901871bd02d9acb7de66b9fb6b4
|
/generated/src/aws-cpp-sdk-application-autoscaling/include/aws/application-autoscaling/model/SuspendedState.h
|
6651f1db5a8f164e15701c371aae495116501d00
|
[
"Apache-2.0",
"MIT",
"JSON"
] |
permissive
|
aws/aws-sdk-cpp
|
aff116ddf9ca2b41e45c47dba1c2b7754935c585
|
9a7606a6c98e13c759032c2e920c7c64a6a35264
|
refs/heads/main
| 2023-08-25T11:16:55.982089
| 2023-08-24T18:14:53
| 2023-08-24T18:14:53
| 35,440,404
| 1,681
| 1,133
|
Apache-2.0
| 2023-09-12T15:59:33
| 2015-05-11T17:57:32
| null |
UTF-8
|
C++
| false
| false
| 6,357
|
h
|
SuspendedState.h
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/application-autoscaling/ApplicationAutoScaling_EXPORTS.h>
namespace Aws
{
namespace Utils
{
namespace Json
{
class JsonValue;
class JsonView;
} // namespace Json
} // namespace Utils
namespace ApplicationAutoScaling
{
namespace Model
{
/**
* <p>Specifies whether the scaling activities for a scalable target are in a
* suspended state. </p><p><h3>See Also:</h3> <a
* href="http://docs.aws.amazon.com/goto/WebAPI/application-autoscaling-2016-02-06/SuspendedState">AWS
* API Reference</a></p>
*/
class SuspendedState
{
public:
AWS_APPLICATIONAUTOSCALING_API SuspendedState();
AWS_APPLICATIONAUTOSCALING_API SuspendedState(Aws::Utils::Json::JsonView jsonValue);
AWS_APPLICATIONAUTOSCALING_API SuspendedState& operator=(Aws::Utils::Json::JsonView jsonValue);
AWS_APPLICATIONAUTOSCALING_API Aws::Utils::Json::JsonValue Jsonize() const;
/**
* <p>Whether scale in by a target tracking scaling policy or a step scaling policy
* is suspended. Set the value to <code>true</code> if you don't want Application
* Auto Scaling to remove capacity when a scaling policy is triggered. The default
* is <code>false</code>. </p>
*/
inline bool GetDynamicScalingInSuspended() const{ return m_dynamicScalingInSuspended; }
/**
* <p>Whether scale in by a target tracking scaling policy or a step scaling policy
* is suspended. Set the value to <code>true</code> if you don't want Application
* Auto Scaling to remove capacity when a scaling policy is triggered. The default
* is <code>false</code>. </p>
*/
inline bool DynamicScalingInSuspendedHasBeenSet() const { return m_dynamicScalingInSuspendedHasBeenSet; }
/**
* <p>Whether scale in by a target tracking scaling policy or a step scaling policy
* is suspended. Set the value to <code>true</code> if you don't want Application
* Auto Scaling to remove capacity when a scaling policy is triggered. The default
* is <code>false</code>. </p>
*/
inline void SetDynamicScalingInSuspended(bool value) { m_dynamicScalingInSuspendedHasBeenSet = true; m_dynamicScalingInSuspended = value; }
/**
* <p>Whether scale in by a target tracking scaling policy or a step scaling policy
* is suspended. Set the value to <code>true</code> if you don't want Application
* Auto Scaling to remove capacity when a scaling policy is triggered. The default
* is <code>false</code>. </p>
*/
inline SuspendedState& WithDynamicScalingInSuspended(bool value) { SetDynamicScalingInSuspended(value); return *this;}
/**
* <p>Whether scale out by a target tracking scaling policy or a step scaling
* policy is suspended. Set the value to <code>true</code> if you don't want
* Application Auto Scaling to add capacity when a scaling policy is triggered. The
* default is <code>false</code>. </p>
*/
inline bool GetDynamicScalingOutSuspended() const{ return m_dynamicScalingOutSuspended; }
/**
* <p>Whether scale out by a target tracking scaling policy or a step scaling
* policy is suspended. Set the value to <code>true</code> if you don't want
* Application Auto Scaling to add capacity when a scaling policy is triggered. The
* default is <code>false</code>. </p>
*/
inline bool DynamicScalingOutSuspendedHasBeenSet() const { return m_dynamicScalingOutSuspendedHasBeenSet; }
/**
* <p>Whether scale out by a target tracking scaling policy or a step scaling
* policy is suspended. Set the value to <code>true</code> if you don't want
* Application Auto Scaling to add capacity when a scaling policy is triggered. The
* default is <code>false</code>. </p>
*/
inline void SetDynamicScalingOutSuspended(bool value) { m_dynamicScalingOutSuspendedHasBeenSet = true; m_dynamicScalingOutSuspended = value; }
/**
* <p>Whether scale out by a target tracking scaling policy or a step scaling
* policy is suspended. Set the value to <code>true</code> if you don't want
* Application Auto Scaling to add capacity when a scaling policy is triggered. The
* default is <code>false</code>. </p>
*/
inline SuspendedState& WithDynamicScalingOutSuspended(bool value) { SetDynamicScalingOutSuspended(value); return *this;}
/**
* <p>Whether scheduled scaling is suspended. Set the value to <code>true</code> if
* you don't want Application Auto Scaling to add or remove capacity by initiating
* scheduled actions. The default is <code>false</code>. </p>
*/
inline bool GetScheduledScalingSuspended() const{ return m_scheduledScalingSuspended; }
/**
* <p>Whether scheduled scaling is suspended. Set the value to <code>true</code> if
* you don't want Application Auto Scaling to add or remove capacity by initiating
* scheduled actions. The default is <code>false</code>. </p>
*/
inline bool ScheduledScalingSuspendedHasBeenSet() const { return m_scheduledScalingSuspendedHasBeenSet; }
/**
* <p>Whether scheduled scaling is suspended. Set the value to <code>true</code> if
* you don't want Application Auto Scaling to add or remove capacity by initiating
* scheduled actions. The default is <code>false</code>. </p>
*/
inline void SetScheduledScalingSuspended(bool value) { m_scheduledScalingSuspendedHasBeenSet = true; m_scheduledScalingSuspended = value; }
/**
* <p>Whether scheduled scaling is suspended. Set the value to <code>true</code> if
* you don't want Application Auto Scaling to add or remove capacity by initiating
* scheduled actions. The default is <code>false</code>. </p>
*/
inline SuspendedState& WithScheduledScalingSuspended(bool value) { SetScheduledScalingSuspended(value); return *this;}
private:
bool m_dynamicScalingInSuspended;
bool m_dynamicScalingInSuspendedHasBeenSet = false;
bool m_dynamicScalingOutSuspended;
bool m_dynamicScalingOutSuspendedHasBeenSet = false;
bool m_scheduledScalingSuspended;
bool m_scheduledScalingSuspendedHasBeenSet = false;
};
} // namespace Model
} // namespace ApplicationAutoScaling
} // namespace Aws
|
91633f5800d4eaa3dcda72f3ba3a5512da46ae42
|
6f460a74aec561106fe1e31d24501b8713686239
|
/problems/2968.cpp
|
c82ed4cb1e0db76f0ef6d5e92299c908cd81cc13
|
[] |
no_license
|
JVelezMed/caribbean-online-judge-solutions
|
0d7a4423e5c340944aedca8134f3d9732fb71980
|
43929a7c90f26f0a1e254797dc1ed8f1f728417c
|
refs/heads/master
| 2020-06-14T20:14:57.216235
| 2019-07-03T19:36:22
| 2019-07-03T19:36:22
| 195,113,656
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,180
|
cpp
|
2968.cpp
|
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
bool isSubsetSum(int n, int sum);
int dogs[6];
int main(){
int cases;
scanf("%d", &cases);
while(cases--) {
int accum = 0;
for (int i = 0; i < 6; ++i) {
scanf("%d", &dogs[i]);
accum += dogs[i];
}
if(accum % 2 == 0) {
if(isSubsetSum(6, accum/2)) {
printf("Tobby puede cruzar\n");
}
else {
printf("Tobby no puede cruzar\n");
}
}
else {
printf("Tobby no puede cruzar\n");
}
}
return 0;
}
bool isSubsetSum(int n, int sum)
{
// Base Cases
if (sum == 0)
return true;
if (n == 0 && sum != 0)
return false;
// If last element is greater than sum, then ignore it
if (dogs[n-1] > sum)
return isSubsetSum(n-1, sum);
/* else, check if sum can be obtained by any of the following
(a) including the last element
(b) excluding the last element */
return isSubsetSum(n-1, sum) || isSubsetSum(n-1, sum-dogs[n-1]);
}
|
0acd0367b0f4f2c237406816e186aefcd74f5963
|
e4460cc5b7b3a6c97ead573d6b17191d12174032
|
/Assignment4/src/Goal.h
|
c12771d76616768e8ec912b0d6de560c3bee0d14
|
[] |
no_license
|
leongyh/CS184
|
b91c7173a746199bed7d595255664eb0be2c266b
|
5d14f7fa05f851b779b40f5caa39725b064d76ee
|
refs/heads/master
| 2021-01-23T03:27:11.909380
| 2014-12-20T04:38:06
| 2014-12-20T04:38:06
| 25,003,484
| 2
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 594
|
h
|
Goal.h
|
#ifndef GOAL_H_
#define GOAL_H_
#include <glm/glm.hpp>
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#endif
#ifdef OSX
#include <GLUT/glut.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/glu.h>
#endif
class Goal{
protected:
glm::vec3 position;
glm::vec3 displacement;
public:
Goal(float x, float y, float z);
Goal(glm::vec3 pos);
virtual ~Goal();
void setPosition(float x, float y, float z);
void setPosition(glm::vec3 p);
void move(float x, float y, float z);
glm::vec3 getPosition();
void draw();
void print();
};
#endif
|
e19f60790e87e7ee18ccf9f9b174c14062e32b67
|
d202b198e7735ed652cd4841ad3754fe05fc1333
|
/Online_Judge/UVA_Solutions/865 - Substitution Cypher.cpp
|
363770acf45f264d642a3c384246991f1ef95055
|
[] |
no_license
|
TanzimRusho/OLD-MATERIALS
|
11ea03752919d15abf0e98e9057f1dd936e7e8d5
|
3a97cb2f9a8002b0e62ecea9a6ba903489c2ae4c
|
refs/heads/master
| 2023-06-01T11:47:30.659574
| 2021-06-15T22:19:28
| 2021-06-15T22:19:28
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 954
|
cpp
|
865 - Substitution Cypher.cpp
|
/*
* Author: Quickgrid ( Asif Ahmed )
* Site: https://quickgrid.wordpress.com
*/
#include<stdio.h>
#include<string.h>
#define N 256
static char text[N];
static char plaintext[N];
static char substitution[N];
static char newLayout[N];
static char output[N];
int main(){
int n;
scanf("%d", &n);
getchar();
getchar();
for(int j = 0; j < n; ++j){
if(j)
printf("\n");
gets(plaintext);
gets(substitution);
for(int i = 0; i < 256; ++i)
newLayout[i] = i;
for(int i = 0; plaintext[i]; ++i)
newLayout[ plaintext[i] ] = substitution[i];
puts(substitution);
puts(plaintext);
while(gets(text) && strlen(text)){
memset(output, 0, sizeof output);
for( int i = 0; i < strlen( text ); ++i )
output[i] = newLayout[ text[i] ];
puts(output);
}
}
return 0;
}
|
9830c33b2af22c2ef91ab069704ca22f2e48f894
|
daa138f0b80188f77519fe01b5921e5d88072678
|
/node/node.h
|
014549da04669cba254543a8883da31272bc34e4
|
[] |
no_license
|
mc-cat-tty/DoorbellCamDaemon
|
e3459bee6256be44e3c82d7f15ce91592ec5a92b
|
8c59d20748eed22b33a65646267c2ff289e11594
|
refs/heads/main
| 2023-08-06T08:54:24.291615
| 2022-07-27T10:58:07
| 2022-07-27T10:58:07
| 491,296,136
| 7
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,548
|
h
|
node.h
|
#pragma once
#include <string>
#include <set>
#include <time.h>
#include <opencv2/opencv.hpp>
#include "../object_detection/object_detection.h"
#include "../fsm_manager/fsm_manager.h"
class Node {
private:
/**
* @brief Private constructor of Node object
*
*/
Node() {};
objdet::ObjectDetector detector; /**< Object that abstract detection from concrete implementation */
fsm::FsmManager fsm; /**< Finite State Machine */
std::string mrl; /**< Media Resource Link */
std::set<std::string> triggers; /**< Set of classes that trigger the doorbell */
public:
/**
* @brief Returns a singleton of class Node
*
* @return Node& is the same every time you call getInstance
*/
[[nodiscard]] static Node& getInstance() {
static Node instance;
return instance;
};
/**
* @brief Set the Detector object
*
* @param object_detector new value of detector attribute
* @return Node& returns the current instance (singleton) of Node
*/
Node& setDetector(const objdet::ObjectDetector &object_detector) {
this->detector = object_detector;
return *this;
};
/**
* @brief Set the Fsm object
*
* @param fsm_manager new value for fsm attribute
* @return Node& returns the current instance (singleton) of Node
*/
Node& setFsm(const fsm::FsmManager &fsm_manager) {
this->fsm = fsm_manager;
return *this;
}
/**
* @brief Set the Mrl object
*
* @param stream_mrl new value of mrl attribute
* @return Node& returns the current instance (singleton) of Node
*/
Node& setMrl(const std::string &stream_mrl) {
this->mrl = stream_mrl;
return *this;
}
/**
* @brief Set the Triggering Classes object
*
* @param triggering_classes new value of triggers attributes
* @return Node& returns the current instance (singleton) of Node
*/
Node& setTriggeringClasses(const std::set<std::string> &triggering_classes) {
this->triggers = triggering_classes;
return *this;
}
/**
* @brief event loop that spins forever (actually, it spins until an exception occurs)
*
*/
[[noreturn]] void loop();
};
|
07d45e34de1c4c67fb7ced9a0f9464c2d9c7d3ef
|
3d31c8b6a4fe8c08a2369ceec3e22c9e18a006da
|
/copycontest/copycontest.ino
|
1b511f1460ac365f5eae30cb029d043d3f3762f4
|
[
"MIT"
] |
permissive
|
Feriixu/RubberToDigi
|
0da13c0d8b1b6cea51e87d45ba40abc5a31aed56
|
4570c4f1d3902ceb928e67d85bb9ce45bcacecc4
|
refs/heads/master
| 2020-05-02T20:44:56.632471
| 2019-04-28T17:34:50
| 2019-04-28T17:34:50
| 153,131,327
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,049
|
ino
|
copycontest.ino
|
#include <DigiKeyboardDe.h>
#include <avr/pgmspace.h>
const char line1[] PROGMEM = "cmd";
const char line4[] PROGMEM = "del copycontest.txt";
const char line6[] PROGMEM = "copy con copycontest.txt";
const char line8[] PROGMEM = "1";
const char line10[] PROGMEM = "2";
const char line12[] PROGMEM = "3";
char buffer[25];
#define GetPsz( x ) (strcpy_P(buffer, (char*)x))
void waitFor( int d ) {DigiKeyboardDe.delay(d);}
void sendModKey( int key, int mod ) { DigiKeyboardDe.sendKeyStroke(key, mod); DigiKeyboardDe.update(); }
void sendKey( int key ) { DigiKeyboardDe.sendKeyStroke(key); DigiKeyboardDe.update(); }
void print(char t[]) {DigiKeyboardDe.print(t); DigiKeyboardDe.update();}
void println(char t[]) {DigiKeyboardDe.println(t); DigiKeyboardDe.update();}
void setup()
{
sendModKey(KEY_R , MOD_GUI_LEFT);
println(GetPsz (line1));
waitFor(200);
println(GetPsz (line4));
println(GetPsz (line6));
println(GetPsz (line8));
println(GetPsz (line10));
println(GetPsz (line12));
sendModKey(KEY_C, MOD_CONTROL_LEFT);
}
void loop() { }
|
04469ad06cb87e5cb75f3cad3a22743be8acb657
|
6e55fefa388c92b9fbebf7b28886503d30a92b92
|
/Rect.cpp
|
4f1d66bff475caef4e130a42e114d67bac0ea9a0
|
[] |
no_license
|
RJHelms84/House-Robot-3D
|
e5bb8cd06349603a3af2d7e363f28f96256b8a62
|
bf203519659f7836085b9d82643548df7d37ea80
|
refs/heads/master
| 2020-06-10T21:10:34.130273
| 2016-12-07T20:26:53
| 2016-12-07T20:26:53
| 75,872,830
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,247
|
cpp
|
Rect.cpp
|
#include "Engine.h"
using namespace std;
namespace Batman {
//default contructor; all vals 0
Rect::Rect() {
left = top = right = bottom = 0;
}
//copy constructor
Rect::Rect(const Rect& R) {
Set(R);
}
//copy constructor
//windows RECT
Rect::Rect(const RECT& R) {
Set(R);
}
//constructor - set int values
Rect::Rect(int l, int t, int r, int b) {
Set(l,r,t,b);
}
//constructor - set double values
Rect::Rect(double l, double t, double r, double b) {
Set(l,t,r,b);
}
//assignment operator
Rect& Rect::operator=(const Rect& R) {
Set(R); return *this;
}
//assignment operator - windows RECT
Rect& Rect::operator=(const RECT& R) {
Set(R); return *this;
}
//Set methods;
//using another Rect
void Rect::Set(const Rect& R) {
left=R.left; top = R.top;
right=R.right; bottom=R.bottom;
}
//using windows RECT
void Rect::Set(const RECT& R) {
left=R.left; top = R.top;
right=R.right; bottom=R.bottom;
}
//using ints
void Rect::Set(int l, int t, int r, int b) {
left=(double)l; top = (double)t;
right=(double)r; bottom=(double)b;
}
//using doubles
void Rect::Set(double l, double t, double r, double b) {
left=l; top = t;
right=r; bottom=b;
}
//send Vector3 point to main Contains
bool Rect::Contains(Vector3 point) {
return Contains(point.getX(), point.getY());
}
//send ints to main Contains
bool Rect::Contains(int x, int y) {
return Contains((double)x,(double)y);
}
//checks to see if an x / y
bool Rect::Contains(double x, double y) {
return (x > left && x < right && y > top && y < bottom);
}
//intersection between 2 rectangles
bool Rect::Intersects(Rect rect) {
//AABB Intersection
//Check min / max of rectangles
if( right < rect.left ||
rect.right < left ||
bottom < rect.top ||
rect.bottom < top
)
return false;
return true;
}
//equality operator comparison includes double rounding
bool Rect::operator==(const Rect& R) const {
return (left==R.left && top == R.top &&
right ==- R.right && bottom == R.bottom);
}
//inequality operator
bool Rect::operator!=(const Rect& V) const {
return (!(*this==V));
}
}
|
e8e62540b439c44b224ec49b22a05715ffc68726
|
4460f143753202f3468586f83c71258aee8678d0
|
/class.cpp
|
48263a40aba5e13c3646e47f0253c76814fafb00
|
[] |
no_license
|
tomzooi/readreq
|
12730180bfcbd448e329181fef70c9e2a1785327
|
5ab8bf81973b0c5f63673e01dff032894b2e1f0d
|
refs/heads/master
| 2016-09-05T14:55:30.240766
| 2015-03-26T06:35:10
| 2015-03-26T06:35:10
| 32,782,512
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,731
|
cpp
|
class.cpp
|
#include <string>
#include <list>
#include "class.h"
#include <iostream>
#include <fstream>
Requirement::Requirement(Requirement * p)
: empty(false), parent(p)
{
}
Requirement::Requirement(std::string l, std::string d, std::string la,Requirement * p) // unused
: empty(false),
level(std::move(l)), description(std::move(d)), label(std::move(la)), parent(p)
{
}
void Requirement::print_json(std::ostream &os, std::string indent) {
os << "{";
indent += '\t';
os
<< "\n" << indent << "\"level\":\"" << level << "\", "
<< "\n" << indent << "\"description\":\"" << description << "\"";
if(label.length() > 1) {
os << ",\n" << indent << "\"label\":\"" << label <<"\"";
}
if (!children.empty()) {
os << ", \"children\":[\n";
bool first = true;
for(auto& child : children) {
if (!first)
os << ',';
first=false;
os << "\n" << indent;
child.print_json(os, indent);
}
os << "]";
}
indent.resize(indent.size() - 1);
os << "\n" << indent << "}";
}
void Requirement::print(std::string indent) {
std::cout << indent << "level: " << level << " description:" << description << " label: " << label << std::endl;
for (Requirement kid : children)
kid.print(indent + '\t');
}
void Requirement::latex(std::ostream &os, std::string name, std::string prefix, std::string indent) {
os << indent << " ";
if (label.length() > 2)
os << "\\label{req:" << label << "} ";
os << name << " " << level << " " << description << std::endl;
for (Requirement kid : children)
kid.latex(os,name,prefix,indent + '#');
}
|
3178e329a95ea43a9afeda7f65d8e3d34cd11ab8
|
4352b5c9e6719d762e6a80e7a7799630d819bca3
|
/tutorials/oldd/box/7.4e-05/k
|
31e93ebbd3b52d60b5e5e4433664ccc85eb7afd4
|
[] |
no_license
|
dashqua/epicProject
|
d6214b57c545110d08ad053e68bc095f1d4dc725
|
54afca50a61c20c541ef43e3d96408ef72f0bcbc
|
refs/heads/master
| 2022-02-28T17:20:20.291864
| 2019-10-28T13:33:16
| 2019-10-28T13:33:16
| 184,294,390
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 26,107
|
k
|
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "7.4e-05";
object k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField nonuniform List<scalar>
2370
(
0.0375033
0.0375
0.0375076
0.0375016
0.0375408
0.0374993
0.0375393
0.0375134
0.0375055
0.0375033
0.0375091
0.0375052
0.0375145
0.0375326
0.0375512
0.0375018
0.0375004
0.0375146
0.0375763
0.0374993
0.0375045
0.0375062
0.0375117
0.0375278
0.0376073
0.0375076
0.0374994
0.0374993
0.0376307
0.0375407
0.0376321
0.0374994
0.0374999
0.0374995
0.0375076
0.0375729
0.0375112
0.0375259
0.0375039
0.0376164
0.0375036
0.037691
0.0375008
0.0375255
0.0375877
0.0375758
0.0375168
0.0375716
0.0374993
0.0377314
0.037516
0.0375036
0.0375443
0.0376211
0.0376058
0.037571
0.0375055
0.0375972
0.0375065
0.0375156
0.0375077
0.037554
0.0375058
0.0374999
0.0375703
0.0375619
0.0374998
0.0375037
0.0375338
0.0375067
0.0375354
0.0375002
0.037578
0.0374995
0.0375702
0.0375001
0.0375619
0.0375851
0.0375032
0.0375532
0.0374994
0.0375132
0.0375062
0.0375097
0.0375017
0.0375986
0.0375047
0.0374993
0.0375659
0.0375036
0.0375701
0.0376153
0.0375244
0.0375737
0.0375314
0.0375297
0.0375236
0.0375223
0.0375751
0.0374996
0.0375492
0.0375172
0.0375218
0.0375044
0.0375209
0.0375075
0.0375131
0.0374993
0.0375016
0.0375492
0.0375003
0.0375818
0.0375559
0.037557
0.0375243
0.0375012
0.0375137
0.0375682
0.0375455
0.0375206
0.0375079
0.0375685
0.0375616
0.0375493
0.0375005
0.0375949
0.0375147
0.0375022
0.0375631
0.0375203
0.0375039
0.0375295
0.0375594
0.0374993
0.0375355
0.0377391
0.0375006
0.0375088
0.0375556
0.0375924
0.0375125
0.0375681
0.0375021
0.0375326
0.037502
0.0375083
0.0375539
0.037527
0.0375376
0.0375269
0.0375815
0.0375805
0.03757
0.0375657
0.0375085
0.0375009
0.0375969
0.0374995
0.0375
0.0375167
0.0375001
0.0375002
0.0375754
0.0375448
0.0375384
0.0375039
0.0375173
0.0375051
0.0375532
0.0375129
0.0375058
0.0375119
0.0375715
0.0375186
0.0375302
0.037521
0.0375061
0.0375132
0.037506
0.0375063
0.0375006
0.0375029
0.0374997
0.0375006
0.0375022
0.0375693
0.0375021
0.037563
0.0375034
0.0375407
0.0375088
0.0375073
0.0375262
0.0375232
0.0375299
0.0375169
0.0374996
0.0375937
0.0375779
0.0374998
0.0375348
0.0374995
0.0376128
0.0375363
0.0375741
0.0374997
0.0375605
0.0376551
0.0375314
0.0374998
0.0375449
0.0374993
0.0374993
0.0375432
0.0375265
0.0375045
0.0374993
0.0374997
0.0375076
0.0375108
0.0374993
0.0374993
0.0375007
0.0374993
0.0375147
0.0374997
0.0375024
0.0375018
0.0375127
0.0375005
0.0375043
0.0375063
0.0374993
0.0375153
0.0374997
0.0375087
0.0374998
0.0374998
0.0374995
0.0375023
0.0374996
0.0374993
0.0374993
0.0374995
0.0374994
0.0374993
0.0375014
0.0375006
0.0374995
0.0374996
0.0374994
0.0374993
0.0375001
0.037505
0.0374993
0.0374994
0.0375008
0.0374993
0.0375062
0.0374993
0.0375
0.0375003
0.0374995
0.0374993
0.0375057
0.0374993
0.0375066
0.0374998
0.0375009
0.0375093
0.0374993
0.0375149
0.0375194
0.0374998
0.0374999
0.0375077
0.0374994
0.0374999
0.0375032
0.0374995
0.0374994
0.0375249
0.0374993
0.037505
0.0375168
0.0375036
0.0375526
0.0374993
0.0374993
0.0375357
0.0375174
0.0374995
0.0375257
0.0375484
0.0374993
0.0374993
0.0374995
0.0374994
0.0375388
0.0375353
0.0374993
0.0375226
0.0375108
0.0374995
0.0374995
0.037508
0.0375253
0.0375047
0.0375129
0.0374993
0.0375019
0.0374994
0.0374993
0.0375267
0.0375003
0.0375014
0.0375075
0.0375178
0.03751
0.0374993
0.0375057
0.0374996
0.0375021
0.0375133
0.0375
0.0374994
0.0375036
0.0375
0.0375192
0.0375139
0.0374999
0.0375017
0.0375098
0.0374995
0.0374998
0.0375082
0.0374998
0.0375048
0.0375071
0.0374994
0.0375097
0.037502
0.0374993
0.0374995
0.0375014
0.0374993
0.0375038
0.0374995
0.0375041
0.0374996
0.0375244
0.0375018
0.0375
0.0375018
0.037529
0.037501
0.0375013
0.0374996
0.0375029
0.0374994
0.0375108
0.0375004
0.0375114
0.0375057
0.0375002
0.0375075
0.0374993
0.0374993
0.0375122
0.0375009
0.0375046
0.0375004
0.037509
0.0374993
0.0374998
0.0374993
0.0375127
0.0375044
0.0375089
0.0375021
0.0375009
0.0375298
0.0375018
0.0375078
0.037501
0.037512
0.0375
0.0375007
0.03751
0.0375334
0.0375507
0.0374993
0.0374993
0.0374996
0.0374996
0.0375061
0.0375022
0.0374993
0.0375273
0.0374993
0.0375064
0.037529
0.0375212
0.0375902
0.0374994
0.0374994
0.0375403
0.0374998
0.0375009
0.0375001
0.0374993
0.0375005
0.0375011
0.0375023
0.0375002
0.0374993
0.0375085
0.0375272
0.0375048
0.0374993
0.0375177
0.0375364
0.0375004
0.0375087
0.0374995
0.037501
0.0375534
0.0375059
0.0374996
0.0374996
0.0374993
0.0374994
0.0375003
0.0374996
0.0375035
0.0374996
0.0374993
0.0375013
0.0375008
0.0375148
0.0375311
0.037528
0.037501
0.0375023
0.0374993
0.0374993
0.0375068
0.0374998
0.0375061
0.0375169
0.0375032
0.0375111
0.0374994
0.0374995
0.0375114
0.0374993
0.0374993
0.0375011
0.0375034
0.0375501
0.0375337
0.0374994
0.0375028
0.0375012
0.0375181
0.0375079
0.0374993
0.0375011
0.0375006
0.0374993
0.0375176
0.0376064
0.0375009
0.0374995
0.0374993
0.0375043
0.0375024
0.0374993
0.0375003
0.0375041
0.0375182
0.0375194
0.0375086
0.0375551
0.037502
0.0375039
0.0375003
0.0375062
0.037501
0.0375002
0.0375047
0.0374993
0.0375016
0.0375114
0.0375169
0.0375072
0.0374993
0.0375155
0.0375226
0.0375117
0.0375012
0.0375127
0.0375031
0.0375031
0.0375001
0.0375009
0.037512
0.0375014
0.0375012
0.0375001
0.0374997
0.0374993
0.0375057
0.0375182
0.0375064
0.037506
0.0375002
0.0375039
0.037532
0.0375021
0.0375283
0.0375252
0.0375
0.0374993
0.0375132
0.0375181
0.0374995
0.0375004
0.0375
0.0375213
0.0375217
0.0375171
0.0374994
0.037519
0.0375026
0.0374993
0.0374995
0.0374994
0.0374996
0.0374999
0.0374993
0.0374998
0.0374996
0.0375043
0.0375027
0.0374997
0.0375009
0.0375219
0.0375204
0.0374993
0.0374997
0.0374995
0.0375008
0.0375077
0.0375395
0.0375025
0.0375184
0.0375031
0.0374993
0.0375161
0.0375232
0.0375044
0.0375351
0.0374995
0.0375001
0.0374993
0.0375176
0.0375189
0.0374993
0.0375136
0.0375
0.0375069
0.0375134
0.0374997
0.0375002
0.0375042
0.0375066
0.037501
0.0375171
0.0374997
0.0374994
0.0375039
0.0375006
0.0375022
0.0375004
0.0374993
0.0375181
0.0374993
0.0374999
0.0375009
0.0374993
0.0375011
0.0375005
0.0375007
0.0375011
0.0374993
0.0374995
0.0374994
0.0375108
0.0374995
0.0375035
0.0374993
0.0375079
0.0375364
0.0375104
0.0375024
0.0375036
0.0374995
0.0375069
0.0374993
0.0374999
0.0375024
0.0375001
0.0375
0.0375111
0.0375174
0.0375029
0.0375018
0.0375045
0.0375009
0.0374993
0.0374999
0.0374997
0.0375017
0.0375043
0.037505
0.0374999
0.0374993
0.0375012
0.0375024
0.0375004
0.0375148
0.0374993
0.0375041
0.0375
0.0375008
0.0374993
0.037513
0.0374995
0.0375014
0.0375015
0.0374994
0.037507
0.0375047
0.0374994
0.037518
0.0374998
0.0374993
0.0375069
0.0374993
0.0375007
0.0374995
0.0375047
0.0374993
0.0375045
0.0374994
0.0375
0.0375002
0.0375149
0.0375002
0.0375042
0.0375078
0.037511
0.037509
0.0375147
0.0375078
0.0375081
0.0374993
0.0374993
0.0375006
0.0375007
0.0374999
0.0374997
0.0375004
0.0375028
0.0374993
0.0375044
0.0374993
0.0375016
0.0375019
0.0374995
0.0374993
0.0374993
0.0375085
0.0374998
0.0374997
0.0374993
0.0375139
0.0375001
0.0375004
0.0374993
0.0375004
0.0374993
0.0375129
0.0375003
0.0374996
0.0375449
0.0375322
0.0375115
0.0375017
0.0374998
0.0374993
0.0375193
0.0375066
0.0375025
0.0375118
0.0374993
0.0374993
0.037505
0.0374993
0.037531
0.0374999
0.0375007
0.0374996
0.0375
0.0374993
0.0375176
0.0374994
0.0375088
0.0374993
0.0374994
0.0374993
0.0375034
0.0374993
0.0375006
0.0375075
0.0374993
0.0375079
0.0374994
0.0375237
0.0375025
0.037504
0.0374996
0.0375326
0.0375027
0.0374999
0.0375001
0.037509
0.0375071
0.0375189
0.0375172
0.0375136
0.0375265
0.0375001
0.0374993
0.0374996
0.0374993
0.0374993
0.0374998
0.0374996
0.0375028
0.0374994
0.0375355
0.0374996
0.0375081
0.0374994
0.0374998
0.0375004
0.0375123
0.0374993
0.0375043
0.0375
0.0375055
0.0375008
0.0374993
0.0374998
0.0374996
0.0374995
0.0374994
0.0375007
0.0375123
0.0374995
0.0375002
0.0374993
0.0374999
0.0375038
0.0375014
0.0375019
0.0374993
0.0375211
0.0375081
0.0374993
0.0375002
0.0375035
0.0374995
0.0374997
0.0374994
0.0374993
0.0375028
0.037502
0.0375163
0.0375116
0.037507
0.0374994
0.037515
0.0374993
0.0375199
0.0375018
0.0374994
0.0375011
0.0375147
0.037527
0.037502
0.0375019
0.0375028
0.0375026
0.0375003
0.0375109
0.0375095
0.0374995
0.0374993
0.037501
0.0375016
0.0375185
0.0374994
0.0374994
0.0374997
0.0375013
0.0375003
0.0374994
0.0375105
0.0375009
0.037524
0.0375042
0.0374997
0.0375015
0.037515
0.0375142
0.0375003
0.0374994
0.0375006
0.0375348
0.0374993
0.0374997
0.0375068
0.0374993
0.0375013
0.0375119
0.0374996
0.0375003
0.0374999
0.037503
0.0375013
0.0375085
0.0375013
0.0375003
0.0375258
0.0375052
0.037532
0.0374993
0.0374998
0.0374998
0.0375148
0.0375007
0.0375149
0.0374994
0.0374996
0.037523
0.0375043
0.0375199
0.0375051
0.0375122
0.0374994
0.0375006
0.037506
0.0375073
0.0375007
0.0375062
0.0375064
0.0375025
0.0374995
0.0375086
0.0375168
0.0375016
0.0375056
0.0375019
0.0374994
0.0374993
0.0375036
0.0375036
0.0374998
0.037513
0.0374994
0.037548
0.0375088
0.0375095
0.0375026
0.0375164
0.0374996
0.0375094
0.0374995
0.0375048
0.0375012
0.0375005
0.0375022
0.0375056
0.0375021
0.0375
0.037522
0.0375124
0.0374995
0.0375385
0.0374999
0.0374993
0.0374994
0.0375001
0.037533
0.0375011
0.0375097
0.037511
0.0375
0.037504
0.0375217
0.0375015
0.037505
0.0375017
0.0375021
0.0375014
0.0374993
0.0375046
0.0374996
0.0375015
0.0375078
0.0374993
0.0375149
0.0375031
0.0375011
0.0375095
0.0374993
0.0375145
0.0375044
0.0375146
0.0374996
0.0375816
0.0375084
0.0375117
0.0375219
0.0375363
0.0375017
0.0375181
0.0374993
0.0374993
0.0375044
0.037517
0.037505
0.0374999
0.0375032
0.0375028
0.0374997
0.0375032
0.0374993
0.0375083
0.0375128
0.0374993
0.0374994
0.0374997
0.0375068
0.0375009
0.037508
0.0374994
0.0374993
0.0375022
0.0375023
0.0375007
0.0374996
0.0374994
0.0375026
0.037507
0.0375006
0.0375146
0.0374993
0.0375111
0.0374993
0.0375234
0.0374993
0.0374993
0.0374993
0.0375008
0.0375061
0.0375016
0.0375481
0.0375026
0.0375025
0.0374993
0.0375109
0.0375035
0.0374997
0.0375001
0.0375002
0.0374993
0.0374996
0.0374993
0.0375242
0.0375043
0.0375005
0.037501
0.0374997
0.0374997
0.0375191
0.0375082
0.0375013
0.0375
0.0375156
0.0375085
0.0374993
0.0374994
0.0375011
0.0374999
0.0375073
0.0375008
0.0375148
0.037502
0.0375
0.0375018
0.0375089
0.0374993
0.0375063
0.0374995
0.0375109
0.0375001
0.0375149
0.0375026
0.0375014
0.0374993
0.0374995
0.0375131
0.0375136
0.037502
0.0374993
0.0375162
0.0375094
0.0375009
0.0374994
0.0374993
0.0375007
0.0375011
0.0375005
0.0375076
0.037502
0.0376097
0.0375005
0.0375213
0.0375018
0.0375036
0.0374995
0.037503
0.0375111
0.0375062
0.0375022
0.0375094
0.037506
0.0375266
0.0375116
0.0374998
0.0374993
0.0375701
0.0375191
0.0376177
0.0374993
0.0374993
0.0375002
0.0374993
0.0374997
0.0375059
0.03751
0.0375002
0.0375004
0.0375008
0.0374998
0.0374993
0.0375023
0.0375086
0.0375043
0.0375007
0.0375003
0.0375072
0.0375016
0.0375019
0.0375005
0.0374994
0.0375056
0.0375019
0.0375019
0.0375004
0.0375105
0.0375007
0.0374994
0.0375289
0.0374994
0.0374993
0.0375252
0.0375064
0.0374994
0.0375101
0.0375014
0.037503
0.0375003
0.0375027
0.0374993
0.0374993
0.0375123
0.0375016
0.0375114
0.0375005
0.0375019
0.0375008
0.0374993
0.0375016
0.037512
0.037509
0.0375001
0.0375135
0.0375048
0.0375117
0.0375196
0.037505
0.0375007
0.0375007
0.0375018
0.0374993
0.0374993
0.0375225
0.0375259
0.0375145
0.0375022
0.0375146
0.0375129
0.0375076
0.0374993
0.0374994
0.0375005
0.0375093
0.0375064
0.0374993
0.0375152
0.0375056
0.0374993
0.0374996
0.0375009
0.0375151
0.0375285
0.0375113
0.0375097
0.0375121
0.0374999
0.0374993
0.0375176
0.0374994
0.0374996
0.0375096
0.0374996
0.0374993
0.0375016
0.0375071
0.0375
0.0375088
0.0375059
0.0375117
0.0375016
0.0374996
0.0375001
0.0375128
0.0375002
0.0375089
0.0374994
0.0375094
0.0375111
0.0375237
0.0374995
0.0374993
0.0375055
0.0375096
0.037515
0.0375173
0.0374993
0.0375031
0.0375133
0.0375
0.0375005
0.0374995
0.0375156
0.0375007
0.0374995
0.0375004
0.0375314
0.0375041
0.0375122
0.0374995
0.0375019
0.0375012
0.0374997
0.037515
0.0374993
0.0375028
0.0374995
0.0374993
0.0375228
0.0375074
0.0375704
0.0375139
0.0375007
0.0375081
0.0374995
0.0375033
0.0375006
0.0374993
0.0374993
0.0375003
0.0375147
0.0374996
0.0375102
0.0374993
0.0374995
0.0374994
0.0375318
0.0375012
0.0375159
0.0375058
0.0375011
0.0375173
0.0375053
0.0374997
0.0375024
0.0375075
0.0375021
0.0375008
0.0375032
0.0374993
0.0375057
0.0375002
0.0375008
0.037521
0.0374997
0.0374998
0.037507
0.0375048
0.0375006
0.0374993
0.037503
0.0374994
0.0375027
0.0374993
0.0374993
0.0375018
0.0375013
0.0375028
0.0374999
0.0375032
0.0375075
0.0375019
0.0374994
0.0375089
0.0374993
0.0375109
0.0374996
0.0374998
0.0375118
0.0374996
0.0374993
0.0374995
0.0375167
0.0375025
0.0374993
0.0375001
0.0375
0.0374993
0.0374996
0.037516
0.0375028
0.0375049
0.0374993
0.0375044
0.0375002
0.0374993
0.037506
0.0375006
0.0374996
0.0375051
0.0374997
0.0374993
0.0375009
0.0375101
0.0375056
0.0375003
0.0374997
0.0375006
0.0375235
0.0375025
0.0375007
0.0374993
0.0374993
0.0375004
0.0374994
0.0375004
0.0374998
0.0374993
0.0374993
0.0375238
0.0375029
0.0374993
0.0375054
0.0375755
0.0375285
0.0375551
0.03754
0.0374994
0.0374995
0.0375132
0.0375394
0.0374993
0.0374993
0.0374993
0.0374999
0.0374993
0.0375077
0.0374993
0.0375263
0.037568
0.0375
0.037514
0.0375003
0.0375146
0.0375017
0.0375062
0.0375163
0.0374996
0.0374995
0.0375055
0.0375301
0.0375141
0.0374993
0.0374993
0.0375017
0.0374999
0.037568
0.0374994
0.0375079
0.0374993
0.0375063
0.0375044
0.0374993
0.0374999
0.0375068
0.0375007
0.0374994
0.0375002
0.0374995
0.0375
0.0375
0.0375017
0.0374999
0.0375029
0.0375162
0.0374994
0.0375141
0.0374994
0.0374993
0.0374993
0.0374996
0.0375124
0.0374994
0.0375053
0.0375046
0.0374996
0.0375023
0.0375033
0.0374996
0.0375115
0.0375072
0.0374993
0.0375049
0.037508
0.037509
0.0375045
0.0375011
0.0375002
0.0374993
0.0375005
0.0375065
0.0375013
0.0375093
0.037506
0.0375005
0.0374994
0.0375004
0.0375234
0.0375267
0.0374993
0.0374993
0.0374994
0.0375025
0.0375026
0.0374993
0.0374993
0.0375001
0.0374997
0.0374993
0.0374993
0.0374997
0.0375025
0.0375004
0.0374993
0.0374997
0.0374999
0.0375002
0.0374993
0.0374998
0.0375012
0.0374993
0.0375002
0.0375025
0.0375018
0.0375004
0.0375016
0.0375032
0.0374993
0.0375026
0.0375072
0.0374998
0.0375013
0.0374993
0.0375018
0.0374993
0.0375011
0.0375025
0.0375002
0.0375115
0.0375028
0.0375146
0.0374993
0.0375041
0.0374999
0.0374994
0.0374993
0.0375142
0.0375102
0.0374994
0.0375069
0.0375239
0.0375008
0.037505
0.0375027
0.037507
0.0375058
0.0375
0.0374993
0.0375042
0.0375042
0.0374994
0.0375105
0.0375053
0.0375001
0.0374997
0.0374993
0.0375002
0.0375242
0.0375545
0.0375029
0.0375044
0.037501
0.0375139
0.0375082
0.0375876
0.0374994
0.0376248
0.0375708
0.0375026
0.0374996
0.0375034
0.0375807
0.0375044
0.0375037
0.0375166
0.0375395
0.0375025
0.0375517
0.037504
0.0375009
0.0375497
0.0374994
0.0374994
0.0374997
0.0375631
0.037558
0.0375849
0.0374994
0.0375373
0.0374993
0.0375049
0.0375055
0.0375123
0.0375085
0.0374993
0.0375242
0.0374993
0.0375001
0.0374993
0.0374994
0.0374993
0.0375025
0.0375008
0.0374993
0.0374993
0.0375
0.0374993
0.0375012
0.0374996
0.0374996
0.0375002
0.0375
0.0374996
0.0374995
0.0375041
0.0374998
0.0375002
0.0375026
0.0374993
0.0374998
0.0375002
0.0374993
0.0375028
0.0374993
0.0374999
0.0375003
0.0375008
0.0375002
0.0374993
0.0374993
0.0374999
0.0375001
0.0374997
0.0374996
0.0374993
0.0374993
0.0374993
0.0374993
0.0375011
0.0375003
0.0374998
0.0375008
0.0375001
0.0375058
0.0374998
0.0374997
0.0374996
0.0375003
0.0374994
0.0375007
0.0374995
0.0374994
0.0374996
0.0375001
0.0374993
0.0374993
0.0374994
0.0374993
0.0374993
0.0374999
0.0374993
0.0374994
0.0374994
0.0374994
0.0375072
0.0374993
0.0374993
0.0374993
0.0375012
0.0374993
0.0375152
0.0375006
0.0375005
0.0374995
0.0374993
0.0375003
0.0374993
0.0375047
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0374994
0.0374995
0.0375005
0.0374993
0.0374993
0.0374995
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0374999
0.0374993
0.0375031
0.0375084
0.0375007
0.0374993
0.0374995
0.0374997
0.0374993
0.0374994
0.0374995
0.0375036
0.0375019
0.0374995
0.0374997
0.0375
0.0375024
0.0375011
0.0374993
0.0374999
0.0375049
0.0374993
0.0375033
0.0374993
0.0375012
0.0374996
0.0374996
0.0374997
0.0375009
0.0374993
0.0374993
0.0374993
0.0375012
0.0374993
0.0375007
0.0375005
0.0375001
0.0374993
0.0374993
0.0375014
0.0375003
0.0375022
0.0374996
0.0374998
0.0375086
0.037505
0.0374993
0.0374993
0.0375001
0.0375002
0.0375003
0.0374993
0.0374993
0.0374995
0.0374994
0.0374993
0.0374993
0.0374993
0.0374993
0.037501
0.0374993
0.0375031
0.0374997
0.0374995
0.0374993
0.0375005
0.0374994
0.0375024
0.0374997
0.0374996
0.0374994
0.0374993
0.0374993
0.0374998
0.0374993
0.0374993
0.0374993
0.0374993
0.0374996
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0375023
0.0374999
0.0375007
0.0374993
0.0374993
0.0374995
0.0374993
0.0374993
0.0375014
0.0374993
0.0375
0.0374995
0.0375
0.0374993
0.0374993
0.0374994
0.0374993
0.0374994
0.0375334
0.0374993
0.0375186
0.0375027
0.0375044
0.0375
0.0374995
0.0374993
0.0375068
0.0374993
0.0374993
0.0374993
0.0374993
0.0374996
0.0374994
0.0374995
0.0374993
0.0375003
0.0375002
0.0374995
0.0375013
0.0375005
0.0374993
0.0375014
0.0375225
0.0374993
0.0375116
0.0375005
0.0374993
0.0374996
0.0375131
0.0374993
0.0375063
0.0374994
0.0375037
0.0374995
0.0375012
0.0374998
0.0374993
0.0374997
0.0374993
0.0375011
0.0374996
0.0374994
0.0374993
0.0374993
0.0375398
0.0374993
0.0374993
0.0374993
0.0375046
0.0374993
0.0375002
0.0374995
0.0375062
0.0375018
0.0374996
0.0375051
0.0374995
0.0375014
0.0375014
0.0374998
0.0374994
0.0374994
0.0374998
0.0374996
0.0375007
0.037502
0.0374994
0.0375001
0.0375001
0.0374993
0.0374993
0.0374996
0.0374997
0.0375012
0.0375006
0.0375011
0.0374999
0.0374994
0.0375036
0.0374996
0.0374995
0.0374993
0.0375027
0.0375017
0.0374993
0.0375
0.0375002
0.0374996
0.0374993
0.0374994
0.0374993
0.0374995
0.0375118
0.0375011
0.0374993
0.0374993
0.0374993
0.0374999
0.0374993
0.0375
0.0375076
0.0374993
0.0374995
0.0374994
0.0375053
0.0374993
0.0374998
0.0374995
0.0374993
0.0374995
0.0374993
0.0374999
0.037501
0.0375015
0.0374994
0.0375007
0.0375008
0.0375001
0.0375009
0.0374993
0.0375
0.0374997
0.0374997
0.0375017
0.0374995
0.0375001
0.0375012
0.037501
0.0375011
0.0374994
0.0374995
0.0374998
0.0375079
0.0375005
0.037501
0.0374993
0.0375001
0.0374995
0.0374997
0.0375
0.037501
0.0375021
0.0375099
0.0375
0.0374994
0.0374993
0.0374993
0.0374993
0.0374997
0.0374994
0.0374994
0.0374993
0.0374997
0.0374995
0.0374993
0.0374993
0.0374994
0.0374993
0.0374993
0.0375001
0.0374995
0.0375033
0.0374993
0.0375001
0.0374994
0.0375
0.0374994
0.0375008
0.0375015
0.0374998
0.0375013
0.0375
0.0375051
0.0374993
0.0374993
0.0375012
0.0375001
0.0374998
0.0375001
0.0375017
0.0375004
0.0374996
0.0374993
0.0374993
0.0374998
0.0374997
0.0374993
0.0375017
0.0374999
0.0375017
0.0374993
0.0374993
0.0374995
0.0375278
0.0375052
0.0375037
0.0374993
0.0375034
0.0375002
0.0374997
0.0375007
0.0375357
0.0375059
0.037508
0.0374993
0.0375058
0.0374993
0.0374993
0.0374993
0.0375147
0.0374999
0.0375007
0.0375
0.0375521
0.0374993
0.0374993
0.0374993
0.0374993
0.0374994
0.0374993
0.0374994
0.0374997
0.0375009
0.0375011
0.0375348
0.037501
0.0375013
0.0375021
0.0375022
0.0375018
0.0374997
0.0374994
0.0374993
0.037503
0.0375014
0.0375022
0.0375019
0.0375013
0.0374993
0.0374993
0.0374998
0.0374993
0.0374993
0.0374994
0.0374994
0.0375008
0.0375306
0.0375122
0.0374993
0.0375074
0.0375528
0.0375
0.0375005
0.0374994
0.0375203
0.0375006
0.0374995
0.0374997
0.0374993
0.0375083
0.0375071
0.0375079
0.0375019
0.0374999
0.0374998
0.0375749
0.0375001
0.0374994
0.0374994
0.0375299
0.0374995
0.0375033
0.0375009
0.0375677
0.0375039
0.0374993
0.0374993
0.0375016
0.0374993
0.037515
0.0374998
0.0375
0.0374994
0.0375196
0.0374993
0.0374993
0.0374993
0.0375087
0.0375009
0.0374995
0.0375029
0.0374994
0.0374999
0.0375562
0.0375009
0.0375014
0.0374998
0.0374993
0.0374993
0.03751
0.0374993
0.037574
0.0375001
0.0374997
0.0374997
0.0375042
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0375046
0.0375046
0.0375073
0.0375046
0.0376471
0.0374994
0.0374993
0.0374996
0.0375597
0.0374996
0.0375035
0.0375714
0.0374994
0.0375
0.0374994
0.0375002
0.0374999
0.0374993
0.0375434
0.0374998
0.0375107
0.0375035
0.0374996
0.0375019
0.0374993
0.0375005
0.0375438
0.0375005
0.0375038
0.0375012
0.0375053
0.0374998
0.0375252
0.0375451
0.0374994
0.0375007
0.0374995
0.0374993
0.0374996
0.0375023
0.0375226
0.0375012
0.0375095
0.0375007
0.0375036
0.0374993
0.0375073
0.0374994
0.0375133
0.0375009
0.0374994
0.0374993
0.0374993
0.0374993
0.0375015
0.0374993
0.037507
0.0375022
0.0374998
0.0374994
0.0375023
0.0375301
0.0375064
0.0375789
0.0375035
0.0375045
0.0374999
0.0374993
0.0375014
0.037515
0.0374994
0.0375786
0.0374994
0.0374993
0.0374993
0.0374993
0.037502
0.0374993
0.0374994
0.0374993
0.037503
0.0374994
0.037542
0.0374995
0.0375002
0.0375019
0.0374996
0.0374999
0.0374999
0.0374996
0.0375456
0.0374998
0.0375648
0.0374998
0.0375194
0.0374999
0.0374993
0.0375003
0.0375027
0.0375003
0.0375563
0.0375009
0.0375102
0.0375024
0.0374993
0.0375006
0.0375441
0.0375
0.0375704
0.0374993
0.0375092
0.0375016
0.0374998
0.0374993
0.0374994
0.0375213
0.0374993
0.0375041
0.0374993
0.0375021
0.0374994
0.0375267
0.0374994
0.0374993
0.0374993
0.0374993
0.0375073
0.0374995
0.0375852
0.037501
0.0374994
0.0374995
0.0375473
0.0374995
0.0375072
0.0374994
0.0374993
0.037503
0.037501
0.0375491
0.0374999
0.0374994
0.0375027
0.0374993
0.0374993
0.0374993
0.0375027
0.0374993
0.0375037
0.0374995
0.0375215
0.0375009
0.0375001
0.0374993
0.037565
0.0374996
0.0374993
0.0374994
0.0375021
0.0374996
0.0374999
0.0375016
0.0374995
0.0375736
0.0374994
0.0374993
0.0375064
0.0374993
0.037504
0.0374993
0.0374993
0.0375779
0.0375007
0.0375844
0.0375005
0.0374997
0.0375008
0.0375014
0.0374993
0.0374998
0.0375556
0.0375006
0.0374997
0.037502
0.0375
0.0375546
0.0375004
0.0375112
0.0374995
0.0374993
0.0375013
0.0374993
0.0375029
0.0374993
0.0374993
0.0375
0.0375482
0.0375
0.0375321
0.0374996
0.0374995
0.0374993
0.0375048
0.0374995
0.0374993
0.0375015
0.0375154
0.0375011
0.0375372
0.0375009
0.0375032
0.0374993
0.0374994
0.0374999
0.0374993
0.0375083
0.0374993
0.0375
0.0375764
0.0375004
0.0375067
0.0375014
0.0375033
0.0375139
0.0375012
0.0375694
0.0375011
0.0375002
0.0375021
0.0374993
0.0374993
0.0374993
0.0375117
0.0374993
0.0374993
0.0374993
0.0374994
0.0374993
0.0375009
0.0375037
0.0375013
0.0375237
0.037501
0.0374998
0.0375026
0.0374995
0.0375018
0.0375002
0.0375164
0.0375002
0.0375121
0.0374993
0.0375659
0.0374995
0.0374993
0.0374996
0.0374999
0.0374998
0.0375013
0.0374995
0.0375549
0.0374993
0.0374994
0.0374993
0.0374993
0.0375148
0.0374993
0.0374994
0.0375074
0.0374995
0.0375571
0.0374994
0.0375003
0.0375022
0.0375029
0.0375018
0.0375467
0.0375012
0.0374995
0.0374999
0.037549
0.0375
0.037516
0.0374998
0.0374995
0.0375018
0.0375004
0.0374994
0.0375
0.0375701
0.0374993
0.037526
0.0375008
0.0375481
0.0375005
0.0374993
0.0375003
0.0375017
0.0375035
0.0375013
0.0374993
0.0374997
0.0375653
0.0374993
0.0375027
0.0374994
0.0375868
0.0374999
0.0374993
0.0374995
0.0375055
0.0375929
0.0375063
0.0375015
0.0375055
0.0375023
0.0375389
0.0374993
0.0375849
0.0375001
0.0375034
0.0374993
0.0374993
0.037501
0.0374993
0.0375072
0.0374993
0.0374993
0.0374993
0.0374993
0.0375025
0.0374993
0.0374995
0.0375001
0.0375031
0.0374997
0.0374995
0.0375001
0.0375565
0.0374993
0.0375
0.0375005
0.0374995
0.0375596
0.0374996
0.0375009
0.0374993
0.037501
0.0375238
0.0375002
0.0375265
0.0375046
0.0374997
0.0375726
0.0375025
0.037568
0.0375022
0.0374993
0.0375036
0.0375378
0.0375009
)
;
boundaryField
{
emptyPatches_empt
{
type empty;
}
top_cyc
{
type freestream;
freestreamValue uniform 0.0375;
value nonuniform List<scalar>
40
(
0.0374998
0.0374995
0.0374994
0.0374995
0.0375002
0.0375044
0.0375021
0.0375064
0.0375032
0.0375012
0.0374997
0.0375
0.0375014
0.0374995
0.0375002
0.0374997
0.0375003
0.0374993
0.0374995
0.0374995
0.0375006
0.0375022
0.0374997
0.0375002
0.0374995
0.0374993
0.0374994
0.0374995
0.0374993
0.0374993
0.0374993
0.0374993
0.0374993
0.0375002
0.0374995
0.0374993
0.0374997
0.0374995
0.0374993
0.0374993
)
;
}
bottom_cyc
{
type freestream;
freestreamValue uniform 0.0375;
value nonuniform List<scalar>
40
(
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0374993
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
0.0375
)
;
}
inlet_cyc
{
type cyclicAMI;
value nonuniform List<scalar>
30
(
0.0375033
0.0375014
0.0375003
0.0375004
0.0374999
0.0375018
0.037501
0.0374998
0.0375001
0.0375021
0.0375018
0.0375063
0.0375037
0.0374997
0.0375001
0.0374993
0.037501
0.0375005
0.0375034
0.0375003
0.0375019
0.0375009
0.0375043
0.0374999
0.037513
0.0375132
0.0375037
0.0374999
0.0375006
0.0375038
)
;
}
outlet_cyc
{
type cyclicAMI;
value nonuniform List<scalar>
30
(
0.037501
0.0374997
0.0375006
0.0375074
0.0375026
0.0375013
0.0375004
0.0374994
0.0374998
0.0375059
0.0375021
0.0375014
0.0375019
0.0375018
0.0375005
0.0375038
0.0375012
0.0374999
0.0375033
0.0374993
0.0375014
0.0375024
0.0375003
0.0375001
0.0375228
0.0375033
0.0375007
0.0375013
0.0375021
0.0374997
)
;
}
}
// ************************************************************************* //
|
|
ddcef4b8d76231817a1c477290e1ecd866110f7e
|
555d6c97cf2f4e1e73e1323ba9fe842a886207a8
|
/CSES/1069.cpp
|
3793c568f2709aadbf7da5a4da214b6cb5cb174d
|
[] |
no_license
|
onecode369/CompetitiveProgramming
|
07e18811fdb607968e85fa08ceea5c59d989914a
|
3d7f1f92734652a9a01ad2dd85a56a99788e1784
|
refs/heads/master
| 2023-05-11T22:09:24.929181
| 2021-06-04T14:21:41
| 2021-06-04T14:21:41
| 340,228,727
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 512
|
cpp
|
1069.cpp
|
#include <bits/stdc++.h>
#define DEBUG(x) cerr << #x << " = " << x << endl
#define MOD 1e9+7
#define INF INT_MAX
#define reset(arr,n,i) fill(arr, arr+n, i)
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string s;
cin >> s;
int cnt = 1,ans = 0;
for(int i=1;i<s.length();i++){
if(s[i] == s[i-1]) cnt++;
else{
ans = max(ans,cnt);
cnt = 1;
}
}
ans = max(ans,cnt);
cout << ans;
return 0;
}
|
e84ab5077f1ada647ee5018b27bf34d291c41129
|
383e7d7f7ef658896a76d89fa3a3d5fb215a0140
|
/core/vil/vil_blocked_image_facade.h
|
582188ea94c45b4dac5f3f74999b946115edc788
|
[] |
no_license
|
aliosmanulusoy/Probabilistic-Volumetric-3D-Reconstruction
|
f9abd69f278a85c0133c3474eaee1c59e2d4f3e2
|
cdb08ed893f88c245bd3c9cff1081182a4eaced9
|
refs/heads/master
| 2021-06-01T23:21:59.861182
| 2016-05-31T09:38:48
| 2016-05-31T09:38:48
| 58,373,814
| 60
| 26
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,676
|
h
|
vil_blocked_image_facade.h
|
// This is core/vil/vil_blocked_image_facade.h
#ifndef vil_blocked_image_facade_h_
#define vil_blocked_image_facade_h_
#ifdef VCL_NEEDS_PRAGMA_INTERFACE
#pragma interface
#endif
//:
// \file
// \brief A blocked image facade for any image resource
// \author J. L. Mundy
//
// this class "wraps" any image resource and provides blocking methods
//
// not used? #include <vcl_compiler.h>
#include <vector>
#include <vil/vil_blocked_image_resource.h>
class vil_blocked_image_facade : public vil_blocked_image_resource
{
public:
vil_blocked_image_facade(const vil_image_resource_sptr &src,
const unsigned sbi=0, const unsigned sbj=0);
virtual ~vil_blocked_image_facade() {}
inline virtual unsigned nplanes() const
{ return src_->nplanes();}
inline virtual unsigned ni() const
{ return src_->ni();}
inline virtual unsigned nj() const
{ return src_->nj();}
//: Block size in columns
inline virtual unsigned size_block_i() const
{ return sbi_;}
//: Block size in rows
inline virtual unsigned size_block_j() const
{ return sbj_;}
//: Number of blocks in image width
inline virtual unsigned n_block_i() const
{ if (sbi_>0)return (src_->ni()+sbi_-1)/sbi_; return 0; }
//: Number of blocks in image height
inline virtual unsigned n_block_j() const
{ if (sbj_>0)return (src_->nj()+sbj_-1)/sbj_; return 0; }
inline virtual enum vil_pixel_format pixel_format() const
{ return src_->pixel_format();}
inline virtual vil_image_view_base_sptr
get_copy_view(unsigned i0, unsigned n_i, unsigned j0, unsigned n_j) const
{ return src_->get_copy_view(i0, n_i, j0, n_j);}
inline virtual bool put_view(const vil_image_view_base& im,
unsigned i0, unsigned j0)
{ return src_->put_view(im, i0, j0);}
//: Block access
virtual vil_image_view_base_sptr get_block( unsigned block_index_i,
unsigned block_index_j ) const;
//: put the block into the resource at the indicated location
virtual bool put_block(unsigned block_index_i,
unsigned block_index_j,
const vil_image_view_base& view);
//: Extra property information
virtual bool get_property(char const* tag, void* property_value = VXL_NULLPTR) const;
protected:
//Internal functions
vil_image_view_base_sptr fill_block(vil_image_view_base_sptr& view) const;
//:the image resource masquerading as a blocked resource
vil_image_resource_sptr src_;
//:block size in i
unsigned sbi_;
//:block size in j
unsigned sbj_;
vil_blocked_image_facade();//not meaningful
};
#endif // vil_blocked_image_facade_h_
|
cdb6bff46638fafe262dfa5e8b021f88131a97fb
|
4c2e6bf2486dac754f543b736f5167043682c96b
|
/ProjectDivaCommand/LyricViewer.cpp
|
46213b66f72f13d2a6add7ff6475be7871d4a0af
|
[
"Apache-2.0"
] |
permissive
|
LinZong/ProjectDivaCommand
|
43616b262f838abd8d9cac5c8c6079e57acae103
|
ad4eeb07eca1b117d7b222e68cc8f3dd343be956
|
refs/heads/master
| 2020-03-17T02:37:17.740339
| 2018-06-05T15:22:42
| 2018-06-05T15:22:42
| 133,197,753
| 3
| 1
| null | null | null | null |
GB18030
|
C++
| false
| false
| 3,799
|
cpp
|
LyricViewer.cpp
|
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <Windows.h>
#include "LyricViewer.h"
#include "ProjectDivaException.h"
using namespace std;
double TotalTime, PastTime;
const int MAX_LYRIC_REPEAT_NUM = 100;
int TotalLine = 0, HeaderLength;
//可能要自己定义一个LyricTime类方便搞
vector<LrcLine> Lrc;
string HeaderTag[] = { "ti:","al:", "ar:", "mu:", "tot" ,"lr:"};
string ThisLrcHeader[6];
DWORD a;
void ReadLyricFiles(char* FilePath)
{
TotalLine = 0;
TotalTime = PastTime = 0;
HeaderLength = 0;
ifstream fin;
fin.open(FilePath);
if (!fin.is_open())
{
throw invalid_argument("Lyric file's path is incorrect or other reason cause fail to read.");
}
if (!Lrc.empty()) Lrc.clear();
string TmpStr;
getline(fin, TmpStr);
while (fin)
{
if (TmpStr != "")
{
LyricAnalyzer(TmpStr);
}
getline(fin, TmpStr);
}
fin.close();
StringTimeToMinSec();
//Print();
}
void LyricHeader(string RawLineLyric)
{
for (int i = 0; i < sizeof(HeaderTag) / sizeof(HeaderTag[0]); i++)
{
if (HeaderTag[i] == RawLineLyric.substr(1, 3))
{
HeaderLength++;
ThisLrcHeader[i] = RawLineLyric;
if (RawLineLyric.substr(1, 3) == "tot")
{
string tstr = RawLineLyric.substr(1, 3);
stringstream tbuffer;
tbuffer << tstr;
tbuffer >> TotalTime;
}
}
}
}
void LyricAnalyzer(string RawLineLrc) throw(InvalidLyricFileException)
{
if (RawLineLrc[0] != '[')
{
throw InvalidLyricFileException();
}
//Check if it's head info.
LyricHeader(RawLineLrc);
int m, n, p = 0;
string timeTemp[MAX_LYRIC_REPEAT_NUM];//保存信息
m = RawLineLrc.find_first_of('[');
n = RawLineLrc.find_first_of(']');
while (m >= 0 && m <= RawLineLrc.length() && n >= 0 && n <= RawLineLrc.length() && RawLineLrc != "")
{
timeTemp[p] = RawLineLrc.substr(m + 1, n - 1);
p++;
RawLineLrc = RawLineLrc.substr(n + 1, RawLineLrc.length());
m = RawLineLrc.find_first_of('[');
n = RawLineLrc.find_first_of(']');
}
string contentTemp = RawLineLrc;
for (int i = 0; i < p; i++)
{
if (TotalLine == 1)
{
cout << endl;
}
LrcLine tline;
tline.StartTime = timeTemp[i];
if (timeTemp[i + 1] != "") //连续的
{
tline.EndTime = timeTemp[i + 1];
cout << timeTemp[i] << endl;
}
if (TotalLine - 1 >= 0 && i == 0) //设置上一个的endTime
{
auto LastIter = Lrc.end();
LastIter--;
LastIter->EndTime = tline.StartTime;
}
tline.LineNum = TotalLine;
tline.LyricContent = contentTemp;
Lrc.push_back(tline);
TotalLine++;
}
}
void Print(int TL)
{
//Show Header
/*for (auto i = Lrc.begin(); i != Lrc.end(); i++)
{
if (i == Lrc.end() - 1)
{
i->MSec = TL-PastTime;
}
FillConsoleOutputCharacter(hd, ' ', 300, { 20 ,24 }, &a);
int thislen = strlen(i->LyricContent.c_str());
WriteConsoleOutputCharacter(hd, i->LyricContent.c_str(), thislen, { (SHORT)(60-thislen/2),24 }, &a);
PastTime += i->MSec;
Sleep(i->MSec);
}*/
}
void StringTimeToMinSec()
{
stringstream buffer;
for (auto i = Lrc.begin(); i < Lrc.begin() + HeaderLength; i++)
{
i->StartTime = "00:00.00";
i->EndTime = "00:00.00";
}
auto i = Lrc.begin();
advance(i, HeaderLength - 1);
i->EndTime = (i + 1)->StartTime;
for (auto i = Lrc.begin(); i != Lrc.end() && i->StartTime != "" && i->EndTime != ""; ++i)
{
buffer.clear();
double Min = 0, Sec = 0, EMin = 0, ESec = 0, Total = 0;
buffer << i->StartTime.substr(0, 2);
buffer >> Min;
buffer.clear();
buffer << i->EndTime.substr(0, 2);
buffer >> EMin;
buffer.clear();
buffer << i->StartTime.substr(3, i->StartTime.length());
buffer >> Sec;
buffer.clear();
buffer << i->EndTime.substr(3, i->EndTime.length());
buffer >> ESec;
Total = (EMin - Min) * 60 * 1000 + (ESec - Sec) * 1000;
i->MSec = Total;
buffer.str("");
}
}
|
6140cf1a345f3101f601d180fc6a3b48d14c713a
|
0a228e2b32d1525fd9faa124bac20b73f3b04866
|
/twoNumberSum2.cpp
|
04d595974ebcd12f04538c8b5ff0a5fe53d6b90d
|
[] |
no_license
|
iangagn/interview_questions_cpp
|
31b5eb6599c2a010784ff4e3fad6350f1c157872
|
5da97ef4e666ab255e8cac484a4a00552de38856
|
refs/heads/main
| 2023-06-10T19:51:38.999357
| 2021-07-07T18:33:51
| 2021-07-07T18:33:51
| 382,937,217
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 687
|
cpp
|
twoNumberSum2.cpp
|
#include <vector>
#include <unordered_set>
using namespace std;
/*
This approach based on a hash table ameliorates time complexity from O(n^2)
to O(n), but space complexity goes from O(1) to O(n) since the
unordered set grow on every iteration.
Time complexity : O(n)
Space complexity : O(n)
*/
vector<int> twoNumberSum(vector<int> array, int targetSum) {
unordered_set<int> arraySet;
int complement;
for (int number : array)
{
complement = targetSum - number;
if (arraySet.find(complement) != arraySet.end())
{
return vector<int>{number, complement};
}
else
{
arraySet.insert(number);
}
}
return {};
}
|
4cdd8636b981e1a6840a70d41958c07428fcfe63
|
eb70adcfcc30ac8301341ccf72ec146de41a1665
|
/src/xmlsettingsdialog/radiogroup.h
|
dfa113ad4e47e82adae6e2673fea26ee6c475a91
|
[] |
no_license
|
Beliaf/leechcraft
|
ff2166070913f2d7ee480f40542ccdf148e49cad
|
0823a7d8f85d11bed0b81e61ddb3bf329f9d5d39
|
refs/heads/master
| 2021-01-18T11:00:38.531356
| 2009-06-14T22:44:13
| 2009-06-14T22:44:13
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,055
|
h
|
radiogroup.h
|
/*
Copyright (c) 2008 by Rudoy Georg <0xd34df00d@gmail.com>
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
*/
#ifndef XMLSETTINGSDIALOG_RADIOGROUP_H
#define XMLSETTINGSDIALOG_RADIOGROUP_H
#include <QWidget>
class QButtonGroup;
class QRadioButton;
namespace LeechCraft
{
class RadioGroup : public QWidget
{
Q_OBJECT
QString Value_;
QButtonGroup *Group_;
public:
RadioGroup (QWidget *parent = 0);
void AddButton (QRadioButton*, bool def = false);
QString GetValue () const;
void SetValue (const QString&);
private slots:
void handleToggled (bool);
signals:
void valueChanged ();
};
};
#endif
|
3ef4090cee2222130c3306ddee1b22ac12b393b4
|
7c7b1050f662ee8e014d39d2633b80eb97d171ba
|
/Sensor.cpp
|
a2e991daa096efe8fc362b58f9d074bbf3d194c9
|
[] |
no_license
|
trotterkt/RiceAlgorithm
|
be618382ee0492033b9b8fb487a3e089677a9cbc
|
00479f69f012715d8531445eff86f16b1ed1dccb
|
refs/heads/master
| 2021-01-17T10:09:29.971678
| 2016-05-13T08:54:19
| 2016-05-13T08:54:19
| 41,396,214
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 21,577
|
cpp
|
Sensor.cpp
|
/*
* Sensor.cpp
*
* Created by: Keir Trotter
* California State University, Fullerton
* MSE, CPSC 597, Graduate Project
*
* Copyright 2016 Keir Trotter
*/
#include <Sensor.h>
#include <iostream>
#include <bitset>
#include <vector>
#include <math.h>
#include <limits.h>
#include <Timing.h>
#include <Endian.h>
#include <DebuggingParameters.h>
#include <ShiftFunctions.h>
#ifdef DEBUG
#include <fstream>
#endif
unsigned char* watchComp1(0);
unsigned char* watchComp2(0);
using namespace std;
using namespace RiceAlgorithm;
Sensor::Sensor(ImagePersistence* image, unsigned int x, unsigned int y, unsigned int z) :
mySource(image), mySamples(0), myXDimension(x), myYDimension(y), myZDimension(z),
myPreprocessor(x, y, z), myWinningEncodedLength((unsigned int) -1)
{
mySamples = mySource->getSampleData(1); //:TODO: only one scan, need to address multiple
// Create the encoding types
size_t bufferSize = myXDimension * myYDimension * myZDimension;
AdaptiveEntropyEncoder* noComp = new AdaptiveEntropyEncoder(bufferSize);
SecondExtensionOption* secondExt = new SecondExtensionOption(bufferSize);
ZeroBlockOption* zeroBlock = new ZeroBlockOption(bufferSize);
SplitSequence* split = new SplitSequence(bufferSize);
myEncoderList.push_back(noComp); // No compression must be the first item
myEncoderList.push_back(secondExt);
myEncoderList.push_back(zeroBlock);
myEncoderList.push_back(split);
// Prepare for the decompression step
groundPtr = new GroundSystem(image);
}
Sensor::~Sensor()
{
delete groundPtr;
}
void Sensor::process()
{
// The goal hear is to form the telemetry of the data
sendHeader();
// :TODO: formalize this a little more
myEncodedBitCount = 19 * BitsPerByte; // Start with header length
//:TODO: Nest this loop in another and iterate over the next residual block
std::vector<AdaptiveEntropyEncoder*>::iterator winningIteration;
CodingSelection winningSelection;
boost::dynamic_bitset<> encodedStream;
boost::dynamic_bitset<> winningEncodedStream;
// To combine encoded blocks, current is dependent on the previous.
// Specifically need the last byte
boost::dynamic_bitset<> previousEncodedStream;
//timestamp_t t0_intermediate, t1_intermediate, t2_intermediate, t3_intermediate;
timestamp_t t0 = getTimestamp();
// Should only need to get the residuals once for a given raw image set
ushort* residualsPtr = myPreprocessor.getResiduals(mySamples);
timestamp_t t1 = getTimestamp();
#ifdef DEBUG
std::ofstream residualsStream;
residualsStream.open("residualsSensor.bin", ios::out | ios::in | ios::binary | ios::trunc);
if (!residualsStream.is_open())
{
exit(EXIT_FAILURE);
}
//const long NumberOfSamples(myXDimension * myYDimension * myZDimension);
const long NumberOfSamples(2000);
for(long index=0; index<NumberOfSamples; index++)
{
cout << "residualsSensor[" << index << "]=" << residualsPtr[index] << endl;
}
residualsStream.write(reinterpret_cast<char*>(residualsPtr), (1024*1024*6*2));
residualsStream.close();
#endif
cout << "Prediction processing time ==> " << fixed << getSecondsDiff(t0, t1) << " seconds"
<< endl;
timestamp_t t2 = getTimestamp();
ulong blockIndex(0);
unsigned int encodedLength(0);
ulong count(0);
long totalSamples = myXDimension * myYDimension * myZDimension;
vector<unsigned char> completeEncoding;
completeEncoding.reserve(totalSamples*sizeof(ushort));
watchComp1 = &completeEncoding[778];
watchComp2 = &completeEncoding[779];
// For a running total of just the encoded data (no header)
ulong currentEncodedSize(0);
//:TODO: This is one of the 1st places where we will start looking
// at applying Amdahl's Law!!!
//totalSamples = 320; // Debugging
for(blockIndex = 0; blockIndex < totalSamples; blockIndex += 32)
{
size_t encodedSize(0);
// Reset for each capture of the winning length
myWinningEncodedLength = (unsigned int) -1;
// t0_intermediate = getTimestamp();
// Loop through each one of the possible encoders
for (std::vector<AdaptiveEntropyEncoder*>::iterator iteration = myEncoderList.begin();
iteration != myEncoderList.end(); ++iteration)
{
encodedStream.clear();
// 1 block at a time
(*iteration)->setSamples(&residualsPtr[blockIndex]);
CodingSelection selection; // This will be most applicable for distinguishing FS and K-split
encodedLength = (*iteration)->encode(encodedStream, selection);
// This basically determines the winner
if (encodedLength < myWinningEncodedLength)
{
*this = *(*iteration);
myWinningEncodedLength = encodedLength;
winningSelection = selection;
encodedSize = (*iteration)->getEncodedBlockSize();
winningEncodedStream = encodedStream;
}
}
// t1_intermediate = getTimestamp();
count++;
switch (winningSelection)
{
case RiceAlgorithm::K0:
case RiceAlgorithm::K1:
case RiceAlgorithm::K2:
case RiceAlgorithm::K3:
case RiceAlgorithm::K4:
case RiceAlgorithm::K5:
case RiceAlgorithm::K6:
case RiceAlgorithm::K7:
case RiceAlgorithm::K8:
case RiceAlgorithm::K9:
case RiceAlgorithm::K10:
case RiceAlgorithm::K11:
case RiceAlgorithm::K12:
case RiceAlgorithm::K13:
#ifdef DEBUG
if(((count >= LowerRange1) && (count <= UpperRange1)) ||
((count >= LowerRange2) && (count <= UpperRange2)))
cout << "And the Winner is: K" << int(winningSelection - 1) << " of code length: "
<< myWinningEncodedLength << " (total=" << myEncodedBitCount << ") on Block Sample [" << blockIndex << "]"
<< ", count=" << count << endl;
#endif
break;
case RiceAlgorithm::SecondExtensionOpt:
#ifdef DEBUG
if(((count >= LowerRange1) && (count <= UpperRange1)) ||
((count >= LowerRange2) && (count <= UpperRange2)))
cout << "And the Winner is: 2ndEXT of code length: " << myWinningEncodedLength
<< " (total=" << myEncodedBitCount << ") on Block Sample [" << blockIndex << "]" << ", count=" << count << endl;
#endif
break;
case RiceAlgorithm::ZeroBlockOpt:
#ifdef DEBUG
if(((count >= LowerRange1) && (count <= UpperRange1)) ||
((count >= LowerRange2) && (count <= UpperRange2)))
cout << "And the Winner is: ZEROBLOCK of code length: " << myWinningEncodedLength
<< " (total=" << myEncodedBitCount << ") on Block Sample [" << blockIndex << "]" << ", count=" << count << endl;
#endif
break;
case RiceAlgorithm::NoCompressionOpt:
#ifdef DEBUG
if(((count >= LowerRange1) && (count <= UpperRange1)) ||
((count >= LowerRange2) && (count <= UpperRange2)))
cout << "And the Winner is: NOCOMP of code length: " << myWinningEncodedLength
<< " (total=" << myEncodedBitCount << ") on Block Sample [" << blockIndex << "]" << ", count=" << count << endl;
#endif
break;
default:
cout << "Unanticipated encoding -- Exiting" << endl;
exit(-1);
}
#ifdef DEBUG
//*******************************************
if(((count >= LowerRange1) && (count <= UpperRange1)) ||
((count >= LowerRange2) && (count <= UpperRange2)))
{
cout << "winning encoding==>" << winningEncodedStream << endl;
}
//*******************************************
#endif
ushort partialBits = myEncodedBitCount % BitsPerByte;
unsigned char lastByte(0);
// When the last byte written is partial, as compared with the
// total bits written, capture it so that it can be merged with
// the next piece of encoded data
if (getLastByte(&lastByte))
{
// #ifdef DEBUG
// if(((count >= LowerRange1) && (count <= UpperRange1)) ||
// ((count >= LowerRange2) && (count <= UpperRange2)))
// cout << "Before partial appendage: " << winningEncodedStream << endl;
// #endif
//
// unsigned int appendedSize = winningEncodedStream.size() + partialBits;
// winningEncodedStream.resize(appendedSize);
// boost::dynamic_bitset<> lastByteStream(winningEncodedStream.size(), ulong(lastByte));
// lastByteStream <<= (winningEncodedStream.size() - BitsPerByte);
// winningEncodedStream |= lastByteStream;
//
// #ifdef DEBUG
// if(((count >= LowerRange1) && (count <= UpperRange1)) ||
// ((count >= LowerRange2) && (count <= UpperRange2)))
// cout << "After partial appendage : " << winningEncodedStream << endl;
// #endif
}
//myEncodedBitCount += (myWinningEncodedLength + CodeOptionBitFieldFundamentalOrNoComp);
myEncodedBitCount += myWinningEncodedLength;
// t2_intermediate = getTimestamp();
static unsigned int lastWinningEncodedLength(0);
// ulong byteCount(0);
// int additionalBits(myEncodedBitCount % BitsPerByte);
// byteCount = (myEncodedBitCount / BitsPerByte);
//*************************************************************
size_t numBlocks(0);
numBlocks = winningEncodedStream.num_blocks();
vector<unsigned long> packedDataBlocks(numBlocks);
boost::to_block_range(winningEncodedStream, packedDataBlocks.begin());
std::reverse(packedDataBlocks.begin(), packedDataBlocks.end());
// Make a char array to manipulate
unsigned char* packedData = reinterpret_cast<unsigned char*>(new char[(packedDataBlocks.size() + 1)* sizeof(unsigned long)]);
memset(packedData, 0, (packedDataBlocks.size() + 1)* sizeof(unsigned long));
unsigned long* packedData2 = new unsigned long[numBlocks];
memset(packedData2, 0, numBlocks * sizeof(unsigned long));
copy(packedDataBlocks.begin(), packedDataBlocks.end(), packedData2);
// not certain why endian swap on each element is nessassary
for(int index=0; index<numBlocks; index++)
{
bigEndianVersusLittleEndian(packedData2[index]);
memcpy(&packedData[index*sizeof(unsigned long)], &packedData2[index], sizeof(unsigned long));
unsigned long temp = packedDataBlocks[index];
bigEndianVersusLittleEndian(temp);
packedDataBlocks[index] = temp;
}
//:KLUDGE: This is very much a kludge to fix the data available
size_t dataBitLength = (packedDataBlocks.size() * sizeof(unsigned long) + 3) * BitsPerByte; // Extra 3 bytes is to allow for shifting
adjustPackeDataPosition(packedData, dataBitLength);
mySource->sendEncodedPacket(packedData, myWinningEncodedLength);
// t3_intermediate = getTimestamp();
}
timestamp_t t3 = getTimestamp();
// cout << "\nRepresentative intermediate Encoding processing times ==> " << fixed
// << "\n(intermediate t0-t1): " << fixed
// << getSecondsDiff(t0_intermediate, t1_intermediate) << " seconds"
// << "\n(intermediate t1-t2): " << fixed
// << getSecondsDiff(t1_intermediate, t2_intermediate) << " seconds"
// << "\n(intermediate t2-t3): " << fixed
// << getSecondsDiff(t2_intermediate, t3_intermediate) << " seconds\n" << endl;
cout << "Encoding processing time ==> " << fixed << getSecondsDiff(t2, t3) << " seconds"
<< endl;
}
void Sensor::sendHeader()
{
// Note: Header is not completely populated for all defined parameters.
// Only what is applicable to the selected test raw data to
// identify identical information. Also, probably not the most
// clean way to fill in fields.
CompressedHeader header = { 0 };
// Collect the structure data
header.xDimension = myXDimension;
header.yDimension = myYDimension;
header.zDimension = myZDimension;
bigEndianVersusLittleEndian(header.xDimension);
bigEndianVersusLittleEndian(header.yDimension);
bigEndianVersusLittleEndian(header.zDimension);
//----------------------------------------------------------------------------
bool signedSamples(false);
bool bsq(true);
header.signSampDynRangeBsq1 |= signedSamples;
header.signSampDynRangeBsq1 <<= 2; // reserved
header.signSampDynRangeBsq1 <<= 4;
header.signSampDynRangeBsq1 |= (DynamicRange & 0xf);
header.signSampDynRangeBsq1 <<= 1;
header.signSampDynRangeBsq1 |= bsq;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool blockType(true);
header.wordSizEncodeMethod |= blockType;
header.wordSizEncodeMethod <<= 2;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
header.predictBandMode |= UserInputPredictionBands;
header.predictBandMode <<= 2;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool neighborSum(true);
header.neighborRegSize |= neighborSum;
header.neighborRegSize <<= 7;
header.neighborRegSize |= RegisterSize;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
header.predictWeightResInit |= (PredictionWeightResolution - 4);
header.predictWeightResInit <<= 4;
unsigned int scaledWeight = log2(PredictionWeightInterval);
header.predictWeightResInit |= (scaledWeight - 4);
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
header.predictWeightInitFinal |= (PredictionWeightInitial + 6);
header.predictWeightInitFinal <<= 4;
header.predictWeightInitFinal |= (PredictionWeightFinal + 6);
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
header.blockSizeRefInterval |= (0x40); // Block size 32 flag
ushort refInterval(ReferenceInterval);
bigEndianVersusLittleEndian(refInterval);
header.blockSizeRefInterval |= refInterval;
//----------------------------------------------------------------------------
boost::dynamic_bitset<unsigned char> packedData;
packCompressedData(header.userData, packedData); // byte 0
packCompressedData(header.xDimension, packedData); // bytes 1,2
packCompressedData(header.yDimension, packedData); // bytes 3,4
packCompressedData(header.zDimension, packedData); // bytes 5,6
packCompressedData(header.signSampDynRangeBsq1, packedData); // byte 7
packCompressedData(header.bsq, packedData); // bytes 8,9
packCompressedData(header.wordSizEncodeMethod, packedData); // bytes 10,11
packCompressedData(header.predictBandMode, packedData); // byte 12
packCompressedData(header.neighborRegSize, packedData); // byte 13
packCompressedData(header.predictWeightResInit, packedData); // byte 14
packCompressedData(header.predictWeightInitFinal, packedData); // byte 15
packCompressedData(header.predictWeightTable, packedData); // byte 16
packCompressedData(header.blockSizeRefInterval, packedData); // bytes 17,18
size_t bitsPerBlock = packedData.bits_per_block;
size_t numBlocks = packedData.num_blocks();
ulong headerSize = HeaderLength*BitsPerByte;
writeCompressedData(packedData, headerSize);
}
void Sensor::sendEncodedSamples(boost::dynamic_bitset<> &encodedStream, unsigned int encodedLength)
{
bool endFlag(false);
// if 0, then whatever is there can be appended and sent
if (encodedLength == 0)
{
endFlag = true;
}
size_t bytes = encodedStream.size() / BitsPerByte;
unsigned int previousSize = encodedStream.size();
if (encodedStream.size() % BitsPerByte)
{
bytes++;
unsigned int newSize = bytes * BitsPerByte;
encodedStream.resize(newSize);
encodedStream <<= (newSize - previousSize);
}
// this does two things - (1) changes the block size from ulong to
// unsigned char and (2) reverses the byte order
// Note that this algorithm was largely arrived at empirically. Looking
// at the data to see what is correct. Keep this in mind when defining
// architectural decisions, and when there may exist reluctance
// after prototyping activities.
boost::dynamic_bitset<unsigned char> convertedStream(encodedStream.size());
for (int byteIndex = 0; byteIndex < bytes; byteIndex++)
{
int targetByte = bytes - byteIndex - 1;
int sourceByte = byteIndex;
for (int bitIndex = 0; bitIndex < BitsPerByte; bitIndex++)
{
int targetBit = (targetByte * BitsPerByte) + bitIndex;
int sourceBit = (sourceByte * BitsPerByte) + bitIndex;
convertedStream[targetBit] = encodedStream[sourceBit];
}
}
ulong totalBitCount(0);
totalBitCount = writeCompressedData(convertedStream, encodedLength, true);
}
ulong Sensor::writeCompressedData(boost::dynamic_bitset<unsigned char> &packedData, size_t bitSize,
bool flag)
{
// Capture the bit sizes, except for header
static ulong blockCount(0);
if(blockCount)
{
mySource->setBlockBitSize((blockCount-1), bitSize);
}
blockCount++;
static ulong totalBitCount(0);
// A non-default bit size might be specified, but this must be adjusted to the nearest
// full bit
if (!bitSize)
{
bitSize = packedData.size();
}
long numberOfBytes = bitSize / BitsPerByte;
if(bitSize % BitsPerByte)
{
numberOfBytes++;
}
//populate vector blocks
vector<unsigned char> packedDataBlocks(packedData.num_blocks());
//populate vector blocks
boost::to_block_range(packedData, packedDataBlocks.begin());
// ushort shiftedBits = totalBitCount % BitsPerByte;
// //=============================================================================
// // Merge first with the last byte
// unsigned char firstByte = packedDataBlocks[0];
// firstByte >>= shiftedBits;
// firstByte |= lastByte;
//
// //=============================================================================
//
//
// // Shift the entire block before adding
// if(shiftedBits)
// {
// unsigned int packetSize = bitSize;
// unsigned char shiftedArray[65]; // room for 32 samples + the id
// std::copy(packedDataBlocks.begin(), packedDataBlocks.end(), shiftedArray);
// shiftLeft(shiftedArray, packetSize, shiftedBits);
// unsigned int newArraySize = (bitSize - shiftedBits)/ BitsPerByte; // this should be whole bytes now
// std::copy(shiftedArray, shiftedArray, packedDataBlocks.begin());
// packedDataBlocks.resize(newArraySize);
// }
//
#ifdef DEBUG
// cout << "Writing Byte:" << mySource->getBytesWritten() << endl;
#endif
//write out each block
for (vector<unsigned char>::iterator it = packedDataBlocks.begin();
it != packedDataBlocks.end(); ++it)
{
if(it == packedDataBlocks.begin())
{
mySource->setEncodedByteLocation(totalBitCount/BitsPerByte);
// bit position is the totalBitCount minus the Header bits
if(totalBitCount)
{
// First time active is after the header. This is the reason from indexing from 2
mySource->setEncodedBitLocation((blockCount-2), totalBitCount - (HeaderLength*BitsPerByte));
}
//continue;
}
//retrieves block and converts it to a char*
mySource->sendEncodedData(reinterpret_cast<unsigned char*>(&*it));
// if we've written the targeted number of bytes
// return
numberOfBytes--;
if (numberOfBytes<0)
{
break;
}
}
totalBitCount += bitSize;
return totalBitCount;
}
bool Sensor::getLastByte(unsigned char *lastByte)
{
// Get the last byte written, and in some cases, reset the file pointer to the one previous
bool partialByteFlag(false);
unsigned int encodedLength = myEncodedBitCount / BitsPerByte;
int additionalBits = myEncodedBitCount % BitsPerByte;
if (additionalBits)
{
encodedLength++;
unsigned char* encodedPtr = mySource->getEncodedData();
*lastByte = encodedPtr[encodedLength - 1];
partialByteFlag = true;
}
if (partialByteFlag)
{
mySource->setNextInsertionByte(encodedLength - 1);
}
return partialByteFlag;
}
void Sensor::getExpectedNextPacketPosition(unsigned char* currentEncodingPtr, int packetBitLength, int &byte, int &bit, ulong count)
{
static double currentTotalLength(0); // Starting after the header
double endLength = currentTotalLength / double(BitsPerByte);
int previousLocationByte = endLength;
int previousLocationBit = (endLength - (long)endLength) * BitsPerByte;
unsigned char selectionBytes[2]; // might span 2 bytes
memcpy(selectionBytes, (currentEncodingPtr + previousLocationByte), 2);
shiftLeft(selectionBytes, 16, previousLocationBit);
selectionBytes[0] >>= (BitsPerByte - CodeOptionBitFieldFundamentalOrNoComp);
RiceAlgorithm::CodingSelection selection;
selection = CodingSelection(selectionBytes[0]);
#ifdef DEBUG
if(((count >= LowerRange1) && (count <= UpperRange1)) ||
((count >= LowerRange2) && (count <= UpperRange2)))
cout << "Current ID:K" << int(selection-1) << endl;
#endif
currentTotalLength += packetBitLength;
endLength = currentTotalLength / double(BitsPerByte);
// compare to what I expect
if(myEncodedBitCount != (currentTotalLength + 152))
{
cout << "For count=" << count << " myEncodedBitCount=" << myEncodedBitCount << " while (currentTotalLength + 152)=" << (currentTotalLength + 152) << endl;
exit(-1);
}
}
|
9b00ae0768cb11decc4d6fadb05548f9dcf08aab
|
e89379a62a334b8d23bfdd2beea0d197824778fe
|
/PriorityQueue/queue.cpp
|
8760e937c62e277a11a709c8105ed64a26e8cda0
|
[] |
no_license
|
rogersBen/DataStructures
|
ee9fd4b20a9a8ba1fcf8a699676f92d0bad7ca3a
|
c93d425d3e7cbd901b04d1057a0902ebbc8c6486
|
refs/heads/master
| 2021-07-19T21:38:17.898097
| 2017-10-29T08:05:43
| 2017-10-29T08:05:43
| 100,327,710
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 9,114
|
cpp
|
queue.cpp
|
using namespace std;
#include <iostream>
#include <fstream>
struct event //server
{
float event_time,event_duration;
int event_type;
};
struct request //customer
{
float arrival_time,service_time;
request*next;
};
int n_serv;
int n_heap;
int n_idle;
event**events;
float now,then;
int arrivals;
request**head;
request**tail;
int*qlen;
void sift_down(void);
void swap(int,int);
void sift_up(void);
int main()
{
char fname[40];
ifstream infile;
cerr<<"Enter the input file name: ";
cin>>fname;
//For each pass
for(int pass= 0;pass<2;pass++)
{
infile.open(fname);
infile>>n_serv;
cout << n_serv << "This\n";
events= new event*[n_serv+1];
for(int i= 0;i<=n_serv;i++)
{
events[i]= new event;
events[i]->event_type= i;
events[i]->event_time= 0.0;
events[i]->event_duration= 0.0;
cout << events[i]->event_time << " " << events[i]->event_duration <<endl;
}
infile>>events[0]->event_time>>events[0]->event_duration;
arrivals= 1;
n_heap= 1;
n_idle= n_serv;
now= then= 0.0;
//If single queue
if(pass==0)
{
head= new request*;
tail= new request*;
qlen= new int;
head[0]= tail[0]= 0;
qlen[0]= 0;
}
else
{
head= new request*[n_serv];
tail= new request*[n_serv];
qlen= new int[n_serv];
for(int i= 0;i<n_serv;i++)
{
head[i]= tail[i]= 0;
qlen[i]= 0;
}
}
//Stats
float*tq= new float[n_serv];
int*served= new int[n_serv];
int*queued= new int[n_serv];
int*qmax= new int[n_serv];
float*busy= new float[n_serv];
//44
//Accumulate service statistics
if(pass==0)
{
//First run is single queue
tq[0]= 0;
}
else
{
for(int s= 0;s<n_serv;s++)
{
//Initialize
tq[s]= 0;
queued[s]= 0;
qmax[s]= 0;
}
}
for(int s= 0;s<n_serv;s++)
{
//still initialize
served[s]= 0;
busy[s]= 0.0;
}
while(n_heap> 0)
{
//20
//Set time to current event
then= now;
now= events[0]->event_time;
# ifdef debug
cout<<endl<<"Debug:"<<endl;
cout<<"It is now: "<<now<<endl;
# endif
# ifdef debug
//Process event
if(events[0]->event_type==0)
{
cout<<"Event is arrival "<<arrivals<<endl;
}
else
{
cout<<"Event is a departure from server "<<events[0]->event_type
<<endl;
}
# endif
# ifdef debug
cout<<"Heap has "<<n_heap<<" events on it."<<endl;
for(int d= 0;d<n_heap;d++)
{
cout<<"Heap["<<d<<"] is of type "<<events[d]->event_type
<<" and contains "<<events[d]->event_time<<" : "
<<events[d]->event_duration<<endl;
}
cout<<"Idle list has "<<n_idle<<" events on it"<<endl;
for(int d= n_heap;d<=n_serv;d++)
{
cout<<"Idle["<<d<<"] is of type "<<events[d]->event_type
<<endl;
}
# endif
# ifdef debug
if(pass==0)
{
if(qlen[0]==0)
cout<<"Queue is empty"<<endl;
else
cout<<"Queue contains "<<qlen[0]<<" items"<<endl;
cout<<" Next item in queue arrived at "<<head[0]->arrival_time
<<" and will take "<<head[0]->service_time<<" to serve"
<<endl;
}
else
{
for(int d= 0;d<n_serv;d++)
{
if(qlen[d]==0)
cout<<"Queue "<<d+1<<" is empty"<<endl;
else
cout<<"Queue "<<d+1<<" contains "<<qlen[d]<<" items"
<<endl;
cout<<" Next item in queue arrived at "
<<head[d]->arrival_time<<" and will take "
<<head[d]->service_time<<" to serve"<<endl;
}
}
# endif
//20
if(events[0]->event_type==0)
//If arrival
{
//22
float service_duration= events[0]->event_duration;
infile>>events[0]->event_time>>events[0]->event_duration;
if(events[0]->event_time!=0.0)
{
arrivals++;
//Arrival is valid
sift_down();
}
else
{
n_heap--;
swap(0,n_heap);
if(n_heap> 0)sift_down();
swap(n_heap,n_serv);
}
if(n_idle==0)
{
//
int q;
if(pass==0)
{
q= 0;
}
else
{
//Find the right q value
//Find the shortest qLength and set it to q
q= 0;
for(int i= 1;i<n_serv;i++)
{
if(qlen[i]<qlen[q])q= i;
}
}
//Really add the request to the queue
request*r= new request;
r->arrival_time= now;
r->service_time= service_duration;
r->next= 0;
//if the Q is empty i need to create the Q
//Otherwise simply add a request on the end
if(head[q]==0)
{
head[q]= r;
}
else
{
tail[q]->next= r;
}
tail[q]= r;
qlen[q]++;
//Do queueing stats accumulation
queued[q]++;
if(qmax[q]<qlen[q])qmax[q]= qlen[q];
}
else
{
//make another server busy
n_heap++;
n_idle--;
events[n_heap-1]->event_time= now+service_duration;
events[n_heap-1]->event_duration= service_duration;
sift_up();
}
}
else //Do a service event 39
//If service
{
//Add a service to the appropriate server
served[events[0]->event_type-1]++;
busy[events[0]->event_type-1]+= events[0]->event_duration;
if(pass==0&&qlen[0]!=0)
{
int i= 0;
//Keep server busy
request*todo= head[i];
head[i]= head[i]->next;
qlen[i]--;
events[0]->event_duration= todo->service_time;
events[0]->event_time= now+todo->service_time;
delete todo;
sift_down();
}
else if(pass==1&&qlen[events[0]->event_type-1]!=0)
{
int i= events[0]->event_type-1;
//Keep server busy
request*todo= head[i];
head[i]= head[i]->next;
qlen[i]--;
events[0]->event_duration= todo->service_time;
events[0]->event_time= now+todo->service_time;
delete todo;
sift_down();
}
else
{
//Make server idle
n_heap--;
n_idle++;
if(n_heap> 0)
{
swap(0,n_heap);
sift_down();
}
}
}
//Statistics 2
if(pass==0)
{
tq[0]= tq[0]+(now-then)*qlen[0];
}
else
{
for(int s= 0;s<n_serv;s++)
{
tq[s]= tq[s]+(now-then)*qlen[s];
}
}
}
cout<<endl
<<"********************************************************************"
<<endl;
if(pass==0) //which pass 48
{
cout<<endl<<"Single queue simulation with "<<n_serv<<
" servers:"<<endl<<endl;
}
else
{
cout<<endl<<"Multiple queue simulation with "<<n_serv<<
" servers:"<<endl<<endl;
}
//Common stats
cout<<" Total Run time = "<<now<<endl;
cout<<" Total Number Served = "<<arrivals<<endl<<endl;
for(int s= 0;s<n_serv;s++)
{
cout<<" Server "<<s+1<<" served "<<served[s]<<
" customers"<<endl;
cout<<" and was busy for a total of "<<busy[s]<<endl;
cout<<" and was idle for a total of "<<now-busy[s]<<endl
<<endl;
}
if(pass==0)
{
//Single queue stats
cout<<" A total of "<<queued[0]<<" customers were queued"
<<endl;
cout<<" with a maximum of "<<qmax[0]<<
" queued at any one time"<<endl<<endl;
cout<<" Average time in queue (all customers) = "<<tq[0]/arrivals
<<endl;
cout<<" Average time in queue (queued customers) = "<<
tq[0]/queued[0]<<endl;
cout<<" Average length of queue = "<<tq[0]/now<<endl;
}
else
{
//Multiple queue stats
int totqueued= 0;
for(int s= 0;s<n_serv;s++)
{
totqueued+= queued[s];
}
cout<<" A total of "<<totqueued<<
" customers were queued: of these:-"<<endl<<endl;
for(int s= 0;s<n_serv;s++)
{
cout<<" "<<queued[s]<<" customers spent time in queue "
<<s<<endl;
cout<<" with a maximum of "<<qmax[s]<<
" queued at any one time"<<endl<<endl;
}
for(int s= 0;s<n_serv;s++)
{
cout<<" Average time in queue for server "<<s+1<<
" (all customers for this server) = "
<<tq[s]/served[s]<<endl;
if(queued[s]==0)
{
cout<<" Average time in queue for server "<<s+1<<
" (queued customers for this server) = "<<0<<endl;
}
else
{
cout<<" Average time in queue for server "<<s+1<<
" (queued customers for this server) = "<<tq[s]/queued[s]
<<endl;
}
cout<<" Average length of queue for server "<<s+1<<" = "<<
tq[s]/now<<endl<<endl;
}
cout<<endl<<
"********************************************************************"<<
endl<<endl;
}
infile.close();
for(int i= 0;i<=n_serv;i++)
{
delete events[i];
}
delete events;
delete head;
delete tail;
delete qlen;
}
return 0;
}
void sift_down()
{
int j,k;
k= 0;
do
{
j= k;
if(2*j+1<n_heap&&events[2*j+1]->event_time<events[k]->event_time)
k= 2*j+1;
if(2*j+2<n_heap&&events[2*j+2]->event_time<events[k]->event_time)
k= 2*j+2;
swap(j,k);
}
while(j!=k);
return;
}
void swap(int i,int j)
{
event*temp;
if(i!=j)
{
temp= events[i];
events[i]= events[j];
events[j]= temp;
}
return;
}
void sift_up()
{
int j,k;
j= n_heap-1;
do
{
k= j;
if(j> 0&&events[j]->event_time<events[(j-1)/2]->event_time)
k= (j-1)/2;
swap(j,k);
}
while(j!=k);
return;
}
|
fca262e9b2b433f7f62cccf506815f6d235a6b37
|
38e587a6b575c329531de8c9391d845867fdbc94
|
/267-Palindrome.Permutation.II.cpp
|
69a695a0d12c40319ac7b232f7658dbec2d40f20
|
[] |
no_license
|
suyinlong/leetcode
|
8844c082aa51cded04057ddbf8ac5d0cbaed719f
|
9c5d451014ae23cbb5ea335a6ff50684e4b1fb97
|
refs/heads/master
| 2021-01-11T17:43:31.922089
| 2017-03-11T15:42:36
| 2017-03-11T15:42:36
| 79,825,384
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,436
|
cpp
|
267-Palindrome.Permutation.II.cpp
|
class Solution {
private:
void backtrack(string &p, string ¤t, vector<bool> &used, vector<string> &ans, char oddChar) {
if (current.size() == p.size()) {
ans.push_back(current);
if (oddChar >= 0) ans.back() += oddChar;
string rp(current);
reverse(rp.begin(), rp.end());
ans.back() += rp;
return;
}
for (int i = 0; i < p.size(); i++) {
if (used[i] || (i > 0 && p[i] == p[i-1] && !used[i-1])) continue;
used[i] = true;
current += p[i];
backtrack(p, current, used, ans, oddChar);
current.pop_back();
used[i] = false;
}
}
public:
vector<string> generatePalindromes(string s) {
vector<string> ans;
vector<int> count(256, 0);
for (char c: s)
count[c] ++;
int odd = 0;
char oddChar = -1;
string p = "";
for (int i = 0; i < 256; i++) {
if (count[i] > 0) {
for (int j = 0; j < (count[i] >> 1); j++)
p += (char)i;
}
if (count[i] % 2 == 1) {
oddChar = i;
odd++;
if (odd > 1) return ans;
}
}
string current = "";
vector<bool> used(p.size(), false);
backtrack(p, current, used, ans, oddChar);
return ans;
}
};
|
5dfae26d4c81589c6c40de29c246ca1cd624504a
|
6eeecfef040f3256da4ff21cb88210e66f6793df
|
/socketcan_elmo_ws/src/cob_canopen_motor/common/include/cob_canopen_motor/SDOSegmented.h
|
669ddc10ed085746062bebc291666b9f882bdb3a
|
[] |
no_license
|
rakeshallampally/elmo
|
3d0a92f837f312f5a4390b43f2b4d9effe4b760c
|
3b3336919c41dcca61ff97cd9e4fc74dd7c69bd9
|
refs/heads/master
| 2020-06-30T12:11:59.042122
| 2019-11-21T04:42:40
| 2019-11-21T04:42:40
| 200,821,373
| 3
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,621
|
h
|
SDOSegmented.h
|
/****************************************************************
*
* Copyright (c) 2010
*
* Fraunhofer Institute for Manufacturing Engineering
* and Automation (IPA)
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Project name: care-o-bot
* ROS stack name: cob_driver
* ROS package name: cob_canopen_motor
* Description: This class is used to collect data that is uploaded to the master in an segmented SDO transfer. Additionally, it includes some administrative functions for this proccess.
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Author: Philipp Köhler
* Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
*
* Date of creation: Mar 2010
* ToDo:
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Fraunhofer Institute for Manufacturing
* Engineering and Automation (IPA) nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License LGPL as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License LGPL for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License LGPL along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
****************************************************************/
#ifndef _SDOSegmented_H
#define _SDOSegmented_H
#include <vector>
/**
* This class is used to collect data that is uploaded to the master in an segmented SDO transfer. Additionally, it includes some administrative functions for this proccess.
* It can be seen as a SDO segmented collector.
*/
class segData {
public:
/**
* States, that are used to describe the current state of the transmission process of the collected segmented SDO transfer.
*/
enum SDOStatusFlag {
SDO_SEG_FREE = 0, /**< SDO collector is ready for a new transmission */
SDO_SEG_WAITING = 3, /**< SDO collector is waiting for the first bytes to receive */
SDO_SEG_COLLECTING = 2, /**< SDO collector is currently collecting data in a segmented SDO transfer */
SDO_SEG_PROCESSING = 1, /**< collection of data is finished but still has to be processed */
};
segData() {
objectID = 0x0000;
objectSubID = 0x00;
toggleBit = false;
statusFlag = SDO_SEG_FREE;
}
~segData() {}
/**
* Clear the SDO segmented collector
*/
void resetTransferData() {
data.clear();
objectID = 0x0000;
objectSubID = 0x00;
toggleBit = false;
statusFlag = SDO_SEG_FREE;
}
//public attributes
//all attributes are public, as this class is used only as ~data array
/**
* combines different status flags and represents the workflow from 3 to 0:
* 3: SDORequest sent, waiting for transmission !If you are expecting a Segmented answer, this must be set during the request!
* 2: SDO process initiated, collecting data
* 1: finished transmission, waiting for data processing
* 0: SDO workflow finished, free for new transmission
*/
int statusFlag;
/**
* Holds the ID of the currently uploading object
*/
int objectID;
/**
* Holds the Sub-ID of the currently uploading object
*/
int objectSubID;
/**
* The toggle bit, that has to be alternated in each confirmation response to a received segment.
*/
bool toggleBit;
/**
* Contains the total number of bytes to be uploaded (if specified by SDO sehmented header)
*/
unsigned int numTotalBytes;
/**
* This vector holds the received data byte-wise
*/
std::vector<unsigned char> data;
};
#endif
|
3d46025d7f89bd697e74954ab3c6cb431890e328
|
cc70452a91a515e4561202cfa32c57197dc0a574
|
/motion8.cpp
|
2476dd7d413a1088d9f59b23157716ecb6d423be
|
[] |
no_license
|
skyfall85/1D_profile
|
6193a791c3207afcce9474208db3b46eef154738
|
05399bd30958236ad5807cb66f1e1c85888d9dae
|
refs/heads/master
| 2020-06-03T14:00:31.613645
| 2015-03-12T14:45:52
| 2015-03-12T14:45:52
| 32,082,362
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,197
|
cpp
|
motion8.cpp
|
/*
Ez a kod az egy komponensu rendszer leirasara lett atalakitva:
kikerul belole az f_s(c,T), illetve csak egy komponensnek lesz benne a latens hoje
2015.02.12. Csütörtök
- most kezdek el ujra ezzel a koddal foglalkozni
- meg kell erteni, hogy pontosan mi mit is csiinal, es ahol lehet, ott egyszerusiteni kellene
*/
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <iomanip>
// #include "functions.h"
#include "find_and_main.h"
#include "free_energy.h"
/*----------------------------------------------------------------
------- VARIABLE DECLARATION STARTS -------
----------------------------------------------------------------*/
double K0, V_m, R;
double eps2,W,dt;
double d,dt0,T,d0,gamma_Ni,xi,c_s,c_l,c0;
double dless_M_phi,Q_Cu,Q_Ni,T_Cu,T_Ni,dless_HT_Plapp,dless_HT,A_phase_noise,k,s_0;
double Ds_rat,dless_Mc,E_t;
double dless_M_theta_s_Plapp,dless_M_theta_l_Plapp,dless_M_theta_s,dless_M_theta_l;
double theta_target;
int num_of_lines; // megadja, hogy hany sort irtam ki
/*----------------------------------------------------------------
------- VARIABLE DECLARATION FINISHES -------
----------------------------------------------------------------*/
/****************************************************************************************************
MAIN STARTS
*****************************************************************************************************/
int main()
{
theta_target=0.5; //!!! itt kell allitani a dtheta-t
FILE *f1, *f2, *f3, *f4;
f1=fopen("other_parameters","r");
f2=fopen("phase_field_parameters","r");
f3=fopen("concentration_parameters","r");
f4=fopen("orientation_parameters","r");
fscanf(f1,"%le %le %le %le %le %le %le %le %le",&d,&dt0,&T,&d0,&gamma_Ni,&xi,&c_s,&c_l,&c0);
fscanf(f2,"%le %le %le %le %le %le %le %le %le %le %le",&dless_M_phi,&W,&Q_Cu,&Q_Ni,&T_Cu,&T_Ni,&dless_HT_Plapp,&dless_HT,&A_phase_noise,&k,&s_0);
fscanf(f3,"%le %le %le",&Ds_rat,&dless_Mc,&E_t);
fscanf(f4,"%le %le %le %le",&dless_M_theta_s_Plapp,&dless_M_theta_l_Plapp,&dless_M_theta_s,&dless_M_theta_l);
// Itt adok meg egyedul sajat valtozokat, a tobbit beolvasom:
calculate_parameters( V_m, R,eps2, K0, gamma_Ni,d0, Q_Cu, Q_Ni, E_t, T, T_Cu, T_Ni, W, dless_HT_Plapp);
int H_enough=0;
dt=0.00625/128.0*1e-4;
while(H_enough!=1)
{
while(theta_target>=0.02)
{
num_of_lines=0;
H_enough=Find_K0( K0, theta_target, dless_HT_Plapp, W, Q_Ni, T, T_Ni);
cout<<"dless_HT_Plapp ciklusban:\t"<<dless_HT_Plapp<<endl;
Main_cicle(W,Q_Ni,T,T_Ni,K0,dless_HT_Plapp,num_of_lines,dt,theta_target);
ofstream out_free_e("free_energy.dat",ios::app);
out_free_e<<theta_target<<"\t"<<free_energy( gamma_Ni, d0, T, T_Ni, Q_Ni, dless_HT_Plapp, xi,num_of_lines)<<endl;
out_free_e.close();
cout<<"Theta-target:\t"<<theta_target<<"\t"<<"Free energy:\t"<<free_energy( gamma_Ni, d0, T, T_Ni, Q_Ni, dless_HT_Plapp, xi,num_of_lines)<<endl;
theta_target>0.2 ? theta_target-=0.05 : theta_target-=0.005;
}
}
return 0;
}
|
3db1cc051b67c00e8609308efd55171978590c42
|
4f267de5c3abde3eaf3a7b89d71cd10d3abad87c
|
/ThirdParty/ShapeOp/ShapeOp_Types.h
|
5221b1e4dac2ab8ebd3e30b2b0ebce8e07805f6a
|
[
"MIT"
] |
permissive
|
MeshGeometry/IogramSource
|
5f627ca3102e85cd4f16801f5ee67557605eb506
|
a82302ccf96177dde3358456c6dc8e597c30509c
|
refs/heads/master
| 2022-02-10T19:19:18.984763
| 2018-01-31T20:09:08
| 2018-01-31T20:09:08
| 83,458,576
| 29
| 17
|
MIT
| 2022-02-01T13:45:33
| 2017-02-28T17:07:02
|
C++
|
UTF-8
|
C++
| false
| false
| 3,189
|
h
|
ShapeOp_Types.h
|
///////////////////////////////////////////////////////////////////////////////
// This file is part of ShapeOp, a lightweight C++ library
// for static and dynamic geometry processing.
//
// Copyright (C) 2014 Sofien Bouaziz <sofien.bouaziz@gmail.com>
// Copyright (C) 2014 LGG EPFL
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
///////////////////////////////////////////////////////////////////////////////
#ifndef TYPES_H
#define TYPES_H
///////////////////////////////////////////////////////////////////////////////
#include "ShapeOp_Common.h"
#include <Eigen/Dense>
#include <Eigen/Sparse>
///////////////////////////////////////////////////////////////////////////////
/** \file
This file redefines EIGEN types using the scalar type ::ShapeOpScalar defined in Common.h.*/
///////////////////////////////////////////////////////////////////////////////
//TODO: For windows 32 bit we may need Eigen::DontAlign
/** \brief Defines Eigen Alignment type.*/
#ifdef SHAPEOP_DONT_ALIGN
#define SHAPEOP_ALIGNMENT Eigen::DontAlign
#else
#define SHAPEOP_ALIGNMENT Eigen::AutoAlign
#endif
///////////////////////////////////////////////////////////////////////////////
/** \brief Namespace of the ShapeOp library.*/
namespace ShapeOp {
typedef ShapeOpScalar Scalar; ///< A scalar type, double or float, as defined in ::ShapeOpScalar in Common.h.
//Dense
template < int Rows, int Cols, int Options = (Eigen::ColMajor | SHAPEOP_ALIGNMENT) >
using MatrixT = Eigen::Matrix<Scalar, Rows, Cols, Options>; ///< A typedef of the dense matrix of Eigen.
typedef MatrixT<2, 1> Vector2; ///< A 2d column vector.
typedef MatrixT<2, 2> Matrix22; ///< A 2 by 2 matrix.
typedef MatrixT<2, 3> Matrix23; ///< A 2 by 3 matrix.
typedef MatrixT<3, 1> Vector3; ///< A 3d column vector.
typedef MatrixT<3, 2> Matrix32; ///< A 3 by 2 matrix.
typedef MatrixT<3, 3> Matrix33; ///< A 3 by 3 matrix.
typedef MatrixT<3, 4> Matrix34; ///< A 3 by 4 matrix.
typedef MatrixT<4, 1> Vector4; ///< A 4d column vector.
typedef MatrixT<4, 4> Matrix44; ///< A 4 by 4 matrix.
typedef MatrixT<3, Eigen::Dynamic> Matrix3X; ///< A 3 by n matrix.
typedef MatrixT<Eigen::Dynamic, 3> MatrixX3; ///< A n by 3 matrix.
typedef MatrixT<Eigen::Dynamic, 1> VectorX; ///< A nd column vector.
typedef MatrixT<Eigen::Dynamic, Eigen::Dynamic> MatrixXX; ///< A n by m matrix.
//Sparse
template<int Options = Eigen::ColMajor>
using SparseMatrixT = Eigen::SparseMatrix<Scalar, Options>; ///< A typedef of the sparse matrix of Eigen.
typedef SparseMatrixT<> SparseMatrix; ///< The default sparse matrix of Eigen.
typedef Eigen::Triplet<Scalar> Triplet; ///< A triplet, used in the sparse triplet representation for matrices.
///////////////////////////////////////////////////////////////////////////////
} // namespace ShapeOp
///////////////////////////////////////////////////////////////////////////////
#endif // TYPES_H
///////////////////////////////////////////////////////////////////////////////
|
d1716077ec0d1579211baa8973d6dfdff14c1d04
|
405fba797f6d33b76f8ce41dbed28817d81b36b7
|
/source/tekwar/src/common.cpp
|
e476831869b8afeae1f2b81b88b1f04ac04b13b0
|
[] |
no_license
|
coelckers/NBlood
|
bed0ed5576906b49fd7da6f8f72622d820f7aa4d
|
cc8d57ee5d6ac8a3c3f400501df25892cb9db6b1
|
refs/heads/master
| 2022-01-21T02:31:42.578207
| 2021-12-05T02:10:52
| 2021-12-05T02:10:52
| 240,122,629
| 5
| 0
| null | 2020-02-12T21:50:29
| 2020-02-12T21:50:28
| null |
UTF-8
|
C++
| false
| false
| 16,417
|
cpp
|
common.cpp
|
//
// Common non-engine code/data for EDuke32 and Mapster32
//
#include "compat.h"
#include "build.h"
#include "baselayer.h"
#include "palette.h"
#include "grpscan.h"
#include "vfs.h"
#include "texcache.h"
#ifdef _WIN32
# include "windows_inc.h"
# include "winbits.h"
#elif defined __APPLE__
# include "osxbits.h"
#endif
#include "common.h"
#include "common_game.h"
struct grpfile_t const* g_selectedGrp;
int32_t g_gameType = GAMEFLAG_TEKWAR;
int g_addonNum = 0;
int r_showfps;
// g_gameNamePtr can point to one of: grpfiles[].name (string literal), string
// literal, malloc'd block (XXX: possible leak)
const char* g_gameNamePtr = NULL;
// grp/con handling
static const char* defaultgamegrp = "tekwar.pk3";
static const char* defaultdeffilename = "tekwar.def";
// g_grpNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char* g_grpNamePtr = NULL;
// g_scriptNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char* g_scriptNamePtr = NULL;
// g_rtsNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char* g_rtsNamePtr = NULL;
void clearGrpNamePtr(void)
{
Xfree(g_grpNamePtr);
// g_grpNamePtr assumed to be assigned to right after
}
void clearScriptNamePtr(void)
{
Xfree(g_scriptNamePtr);
// g_scriptNamePtr assumed to be assigned to right after
}
const char* G_DefaultGrpFile(void)
{
return defaultgamegrp;
}
const char* G_DefaultDefFile(void)
{
return defaultdeffilename;
}
const char* G_GrpFile(void)
{
return (g_grpNamePtr == NULL) ? G_DefaultGrpFile() : g_grpNamePtr;
}
const char* G_DefFile(void)
{
return (g_defNamePtr == NULL) ? G_DefaultDefFile() : g_defNamePtr;
}
//////////
// Set up new-style multi-psky handling.
void G_InitMultiPsky(int CLOUDYOCEAN__DYN, int MOONSKY1__DYN, int BIGORBIT1__DYN, int LA__DYN)
{
// When adding other multi-skies, take care that the tileofs[] values are
// <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be
// set as tight as possible.)
// The default sky properties (all others are implicitly zero):
psky_t* sky = tileSetupSky(DEFAULTPSKY);
sky->lognumtiles = 3;
sky->horizfrac = 32768;
// CLOUDYOCEAN
// Aligns with the drawn scene horizon because it has one itself.
sky = tileSetupSky(CLOUDYOCEAN__DYN);
sky->lognumtiles = 3;
sky->horizfrac = 65536;
// MOONSKY1
// earth mountain mountain sun
sky = tileSetupSky(MOONSKY1__DYN);
sky->lognumtiles = 3;
sky->horizfrac = 32768;
sky->tileofs[6] = 1;
sky->tileofs[1] = 2;
sky->tileofs[4] = 2;
sky->tileofs[2] = 3;
// BIGORBIT1 // orbit
// earth1 2 3 moon/sun
sky = tileSetupSky(BIGORBIT1__DYN);
sky->lognumtiles = 3;
sky->horizfrac = 32768;
sky->tileofs[5] = 1;
sky->tileofs[6] = 2;
sky->tileofs[7] = 3;
sky->tileofs[2] = 4;
// LA // la city
// earth1 2 3 moon/sun
sky = tileSetupSky(LA__DYN);
sky->lognumtiles = 3;
sky->horizfrac = 16384 + 1024;
sky->tileofs[0] = 1;
sky->tileofs[1] = 2;
sky->tileofs[2] = 1;
sky->tileofs[3] = 3;
sky->tileofs[4] = 4;
sky->tileofs[5] = 0;
sky->tileofs[6] = 2;
sky->tileofs[7] = 3;
#if 0
// This assertion should hold. See note above.
for (bssize_t i = 0; i < pskynummultis; ++i)
for (bssize_t j = 0; j < (1 << multipsky[i].lognumtiles); ++j)
Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX);
#endif
}
void G_SetupGlobalPsky(void)
{
int skyIdx = 0;
// NOTE: Loop must be running backwards for the same behavior as the game
// (greatest sector index with matching parallaxed sky takes precedence).
for (int i = numsectors - 1; i >= 0; i--)
{
if (sector[i].ceilingstat & 1)
{
skyIdx = getpskyidx(sector[i].ceilingpicnum);
if (skyIdx > 0)
break;
}
}
g_pskyidx = skyIdx;
}
//////////
static char g_rootDir[BMAX_PATH];
int g_useCwd;
int32_t g_groupFileHandle;
static struct strllist* CommandPaths, * CommandGrps;
void G_ExtPreInit(int32_t argc, char const* const* argv)
{
g_useCwd = G_CheckCmdSwitch(argc, argv, "-usecwd");
#ifdef _WIN32
GetModuleFileName(NULL, g_rootDir, BMAX_PATH);
Bcorrectfilename(g_rootDir, 1);
//buildvfs_chdir(g_rootDir);
#else
buildvfs_getcwd(g_rootDir, BMAX_PATH);
strcat(g_rootDir, "/");
#endif
}
void G_ExtInit(void)
{
char cwd[BMAX_PATH];
#ifdef EDUKE32_OSX
char* appdir = Bgetappdir();
addsearchpath(appdir);
Xfree(appdir);
#endif
#ifdef USE_PHYSFS
strncpy(cwd, PHYSFS_getBaseDir(), ARRAY_SIZE(cwd));
cwd[ARRAY_SIZE(cwd) - 1] = '\0';
#else
if (buildvfs_getcwd(cwd, ARRAY_SIZE(cwd)) && Bstrcmp(cwd, "/") != 0)
#endif
addsearchpath(cwd);
// TODO:
if (CommandPaths)
{
int32_t i;
struct strllist* s;
while (CommandPaths)
{
s = CommandPaths->next;
i = addsearchpath(CommandPaths->str);
if (i < 0)
{
initprintf("Failed adding %s for game data: %s\n", CommandPaths->str,
i == -1 ? "not a directory" : "no such directory");
}
Xfree(CommandPaths->str);
Xfree(CommandPaths);
CommandPaths = s;
}
}
#if defined(_WIN32) && !defined(EDUKE32_STANDALONE)
if (buildvfs_exists("user_profiles_enabled"))
#else
if (g_useCwd == 0 && !buildvfs_exists("user_profiles_disabled"))
#endif
{
char* homedir;
int32_t asperr;
if ((homedir = Bgethomedir()))
{
Bsnprintf(cwd, ARRAY_SIZE(cwd), "%s/"
#if defined(_WIN32)
APPNAME
#elif defined(GEKKO)
"apps/" APPBASENAME
#else
".config/" APPBASENAME
#endif
, homedir);
asperr = addsearchpath(cwd);
if (asperr == -2)
{
if (buildvfs_mkdir(cwd, S_IRWXU) == 0) asperr = addsearchpath(cwd);
else asperr = -1;
}
if (asperr == 0)
buildvfs_chdir(cwd);
Xfree(homedir);
}
}
}
void G_ScanGroups(void)
{
ScanGroups();
g_selectedGrp = NULL;
char const* const currentGrp = G_GrpFile();
for (grpfile_t const* fg = foundgrps; fg; fg = fg->next)
{
if (!Bstrcasecmp(fg->filename, currentGrp))
{
g_selectedGrp = fg;
break;
}
}
if (g_selectedGrp == NULL)
g_selectedGrp = foundgrps;
}
static int32_t G_TryLoadingGrp(char const* const grpfile)
{
int32_t i;
if ((i = initgroupfile(grpfile)) == -1)
initprintf("Warning: could not find main data file \"%s\"!\n", grpfile);
else
initprintf("Using \"%s\" as main game data file.\n", grpfile);
return i;
}
static int32_t G_LoadGrpDependencyChain(grpfile_t const* const grp)
{
if (!grp)
return -1;
if (grp->type->dependency && grp->type->dependency != grp->type->crcval)
G_LoadGrpDependencyChain(FindGroup(grp->type->dependency));
int32_t const i = G_TryLoadingGrp(grp->filename);
return i;
}
void G_LoadGroups(int32_t autoload)
{
if (g_modDir[0] != '/')
{
char cwd[BMAX_PATH];
Bstrcat(g_rootDir, g_modDir);
addsearchpath(g_rootDir);
// addsearchpath(mod_dir);
char path[BMAX_PATH];
if (buildvfs_getcwd(cwd, BMAX_PATH))
{
Bsnprintf(path, sizeof(path), "%s/%s", cwd, g_modDir);
if (!Bstrcmp(g_rootDir, path))
{
if (addsearchpath(path) == -2)
if (buildvfs_mkdir(path, S_IRWXU) == 0)
addsearchpath(path);
}
}
#ifdef USE_OPENGL
Bsnprintf(path, sizeof(path), "%s/%s", g_modDir, TEXCACHEFILE);
Bstrcpy(TEXCACHEFILE, path);
#endif
}
const char* grpfile;
int32_t i;
if ((i = G_LoadGrpDependencyChain(g_selectedGrp)) != -1)
{
grpfile = g_selectedGrp->filename;
clearGrpNamePtr();
g_grpNamePtr = dup_filename(grpfile);
grpinfo_t const* const type = g_selectedGrp->type;
g_gameType = type->game;
g_gameNamePtr = type->name;
if (type->defname && g_defNamePtr == NULL)
g_defNamePtr = dup_filename(type->defname);
}
else
{
grpfile = G_GrpFile();
i = G_TryLoadingGrp(grpfile);
}
if (autoload)
{
G_LoadGroupsInDir("autoload");
if (i != -1)
G_DoAutoload(grpfile);
}
if (g_modDir[0] != '/')
G_LoadGroupsInDir(g_modDir);
loaddefinitions_game(G_DefFile(), TRUE);
struct strllist* s;
int const bakpathsearchmode = pathsearchmode;
pathsearchmode = 1;
while (CommandGrps)
{
int32_t j;
s = CommandGrps->next;
if ((j = initgroupfile(CommandGrps->str)) == -1)
initprintf("Could not find file \"%s\".\n", CommandGrps->str);
else
{
g_groupFileHandle = j;
initprintf("Using file \"%s\" as game data.\n", CommandGrps->str);
if (autoload)
G_DoAutoload(CommandGrps->str);
}
Xfree(CommandGrps->str);
Xfree(CommandGrps);
CommandGrps = s;
}
pathsearchmode = bakpathsearchmode;
}
void G_CleanupSearchPaths(void)
{
removesearchpaths_withuser(SEARCHPATH_REMOVE);
}
//////////
GrowArray<char*> g_scriptModules;
void G_AddGroup(const char* buffer)
{
char buf[BMAX_PATH];
struct strllist* s = (struct strllist*)Xcalloc(1, sizeof(struct strllist));
Bstrcpy(buf, buffer);
if (Bstrchr(buf, '.') == 0)
Bstrcat(buf, ".grp");
s->str = Xstrdup(buf);
if (CommandGrps)
{
struct strllist* t;
for (t = CommandGrps; t->next; t = t->next);
t->next = s;
return;
}
CommandGrps = s;
}
void G_AddPath(const char* buffer)
{
struct strllist* s = (struct strllist*)Xcalloc(1, sizeof(struct strllist));
s->str = Xstrdup(buffer);
if (CommandPaths)
{
struct strllist* t;
for (t = CommandPaths; t->next; t = t->next);
t->next = s;
return;
}
CommandPaths = s;
}
void G_AddCon(const char* buffer)
{
clearScriptNamePtr();
g_scriptNamePtr = dup_filename(buffer);
initprintf("Using CON file \"%s\".\n", g_scriptNamePtr);
}
void G_AddConModule(const char* buffer)
{
g_scriptModules.append(Xstrdup(buffer));
}
//////////
// loads all group (grp, zip, pk3/4) files in the given directory
void G_LoadGroupsInDir(const char* dirname)
{
static const char* extensions[] = { "*.grp", "*.zip", "*.ssi", "*.pk3", "*.pk4" };
char buf[BMAX_PATH];
fnlist_t fnlist = FNLIST_INITIALIZER;
for (auto& extension : extensions)
{
BUILDVFS_FIND_REC* rec;
fnlist_getnames(&fnlist, dirname, extension, -1, 0);
for (rec = fnlist.findfiles; rec; rec = rec->next)
{
Bsnprintf(buf, sizeof(buf), "%s/%s", dirname, rec->name);
initprintf("Using group file \"%s\".\n", buf);
initgroupfile(buf);
}
fnlist_clearnames(&fnlist);
}
}
void G_DoAutoload(const char* dirname)
{
char buf[BMAX_PATH];
Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname);
G_LoadGroupsInDir(buf);
}
//////////
void G_LoadLookups(void)
{
int32_t j;
buildvfs_kfd fp;
if ((fp = kopen4loadfrommod("lookup.dat", 0)) == buildvfs_kfd_invalid)
if ((fp = kopen4loadfrommod("lookup.dat", 1)) == buildvfs_kfd_invalid)
return;
j = paletteLoadLookupTable(fp);
if (j < 0)
{
if (j == -1)
initprintf("ERROR loading \"lookup.dat\": failed reading enough data.\n");
return kclose(fp);
}
uint8_t paldata[768];
for (j = 1; j <= 5; j++)
{
// Account for TITLE and REALMS swap between basepal number and on-disk order.
int32_t basepalnum = (j == 3 || j == 4) ? 4 + 3 - j : j;
if (kread_and_test(fp, paldata, 768))
return kclose(fp);
for (unsigned char& k : paldata)
k <<= 2;
paletteSetColorTable(basepalnum, paldata);
}
kclose(fp);
}
//////////
#ifdef FORMAT_UPGRADE_ELIGIBLE
int g_maybeUpgradeSoundFormats = 1;
static buildvfs_kfd S_TryFormats(char* const testfn, char* const fn_suffix, char const searchfirst)
{
if (!g_maybeUpgradeSoundFormats)
return buildvfs_kfd_invalid;
static char const* extensions[] =
{
#ifdef HAVE_FLAC
".flac",
#endif
#ifdef HAVE_VORBIS
".ogg",
#endif
};
for (char const* ext : extensions)
{
Bstrcpy(fn_suffix, ext);
buildvfs_kfd const fp = kopen4loadfrommod(testfn, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
return buildvfs_kfd_invalid;
}
static buildvfs_kfd S_TryExtensionReplacements(char* const testfn, char const searchfirst, uint8_t const ismusic)
{
char* extension = Bstrrchr(testfn, '.');
char* const fn_end = Bstrchr(testfn, '\0');
// ex: grabbag.voc --> grabbag_voc.*
if (extension != NULL)
{
*extension = '_';
buildvfs_kfd const fp = S_TryFormats(testfn, fn_end, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
else
{
extension = fn_end;
}
// ex: grabbag.mid --> grabbag.*
if (ismusic)
{
buildvfs_kfd const fp = S_TryFormats(testfn, extension, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
return buildvfs_kfd_invalid;
}
buildvfs_kfd S_OpenAudio(const char* fn, char searchfirst, uint8_t const ismusic)
{
buildvfs_kfd const origfp = kopen4loadfrommod(fn, searchfirst);
#ifndef USE_PHYSFS
char const* const origparent = origfp != buildvfs_kfd_invalid ? kfileparent(origfp) : NULL;
uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0;
auto testfn = (char*)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
#else
auto testfn = (char*)Xmalloc(Bstrlen(fn) + 12);
#endif
// look in ./
// ex: ./grabbag.mid
Bstrcpy(testfn, fn);
buildvfs_kfd fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp != buildvfs_kfd_invalid)
goto success;
#ifndef USE_PHYSFS
// look in ./music/<file's parent GRP name>/
// ex: ./music/duke3d/grabbag.mid
// ex: ./music/nwinter/grabbag.mid
if (origparent != NULL)
{
char const* const parentextension = Bstrrchr(origparent, '.');
uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength;
Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn);
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp != buildvfs_kfd_invalid)
goto success;
}
// look in ./music/
// ex: ./music/grabbag.mid
Bsprintf(testfn, "music/%s", fn);
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp != buildvfs_kfd_invalid)
goto success;
#endif
Xfree(testfn);
return origfp;
success:
Xfree(testfn);
kclose(origfp);
return fp;
}
void G_Polymer_UnInit(void) { }
static inline int32_t calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk)
{
// if (!((ud.show_help == 0 && (!g_netServer && ud.multimode < 2) && ((g_player[myconnectindex].ps->gm & MODE_MENU) == 0)) ||
// (g_netServer || ud.multimode > 1) ||
// ud.recstat == 2) ||
// ud.pause_on)
// {
// return 65536;
// }
/* TODO
if (bRecord || bPlayback || nFreeze != 0 || bCamera || bPause)
return 65536;
*/
int32_t rfreq = (refreshfreq != -1 ? refreshfreq : 60);
uint64_t elapsedFrames = tabledivide64(((uint64_t)(totalclk - ototalclk).toScale16()) * rfreq, 65536 * 120);
#if 0
//POGO: additional debug info for testing purposes
OSD_Printf("Elapsed frames: %" PRIu64 ", smoothratio: %" PRIu64 "\n", elapsedFrames, tabledivide64(65536 * elapsedFrames * 30, rfreq));
#endif
return clamp(tabledivide64(65536 * elapsedFrames * 30, rfreq), 0, 65536);
}
#endif
|
380ca9356d950b98de00841e6cc520513f548bf0
|
aaa403c4b4b0a65eeada6d420a17a7cb3a5a1573
|
/challenges/amt/amt/exception.h
|
5145c4185332f3990f5c52f5f3b6a6828478be84
|
[] |
no_license
|
huyuji/garden
|
afd557757feb49e1a7ed270364480a843f45ffce
|
04b8cbfa48c349624d71b6f6c57d71bdab1046b3
|
refs/heads/master
| 2023-03-20T00:07:25.706631
| 2022-12-21T02:58:17
| 2022-12-21T02:58:17
| 33,455,465
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 418
|
h
|
exception.h
|
#pragma once
#ifndef id1A6C7CB0_32BD_4ACE_BDAD4FDD1B0FA29D
#define id1A6C7CB0_32BD_4ACE_BDAD4FDD1B0FA29D
#include <exception>
namespace AMT
{
class AMTException : public std::exception
{
public:
explicit AMTException(const std::string& what) : what_(what)
{
};
const char* what() const { return what_.c_str(); };
private:
const std::string what_;
};
}//end of namespace AMT
#endif // header
|
125c5aa2b87d088a5f818b7c2b52190bba027849
|
178e83cc613c9fc527e7352417cd0c1baaf7bd7c
|
/beginner_contest/127d.cpp
|
8eed4d1aab00c5ae3f3ddc717d6afedd57c79588
|
[] |
no_license
|
shohirose/atcoder
|
658d32e5c79e198cbba3e5afa34a49c5504a9878
|
6ebf9cd39fe6c247fe27b9cf4c09f5020cc67bce
|
refs/heads/master
| 2021-06-08T13:40:19.932763
| 2021-05-13T06:33:56
| 2021-05-13T06:33:56
| 165,779,995
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 755
|
cpp
|
127d.cpp
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
struct Pair {
std::size_t b;
std::size_t c;
};
int main() {
std::size_t n, m;
std::cin >> n >> m;
std::vector<std::size_t> a(n);
for (auto&& ai : a) std::cin >> ai;
std::sort(a.begin(), a.end());
std::vector<Pair> pairs(m);
for (auto&& p : pairs) std::cin >> p.b >> p.c;
std::sort(pairs.begin(), pairs.end(),
[](const auto& p1, const auto& p2) { return p1.c > p2.c; });
std::size_t k = 0;
for (auto&& p : pairs) {
for (std::size_t j = 0; j < p.b; ++j) {
if (a[k] < p.c)
a[k++] = p.c;
else
break;
}
}
const auto sum = std::accumulate(a.begin(), a.end(), 0ULL);
std::cout << sum << std::endl;
}
|
bbc65bba5404d2a968a4818a037e37b39305ebe9
|
27a4c694cd8e475ca00747483151927a4e244e96
|
/chapter_6/6.47.cpp
|
c5f050e60ff3950f5dd7c6dba9364ad7fc3a3929
|
[] |
no_license
|
Sinopse/Cpp_primer
|
cd6f09ae577f06a5b1c4fbf1ccb38610b0dcffe8
|
60aaba7815441f3e03d691a5d2c19547f07636ad
|
refs/heads/master
| 2023-03-11T19:07:50.114417
| 2021-03-02T14:18:40
| 2021-03-02T14:18:40
| 313,850,171
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 508
|
cpp
|
6.47.cpp
|
#include <iostream>
#include <vector>
// write a recursive function to print out contensts of a vector
int print_vec(std::vector<int> veci, size_t idx) {
#ifndef NDEBUG
std::cerr << __func__ << ": current index is " << idx << std::endl;
#endif
auto end = veci.end();
int elem = veci[idx];
if (elem != *end) {
std::cout << elem << std::endl;
++idx;
return print_vec(veci, idx);
}
return 0;
}
int main() {
std::vector<int> veci(10, 1);
print_vec(veci, 0);
return 0;
}
|
117eaa5adb031dfa5d2a9f30fb52e0333397fff0
|
b429696fa4f09804bb59efe5b28d55c4b7bc6d9f
|
/mainwindow.cpp
|
a86b20bbe150eb0b64b0039483bbfa40f1c6ce60
|
[] |
no_license
|
kinshuk-kotecha/Omni_Wheelbase_Emulator
|
f0e488aa05223560654e996d03a6c0721d598699
|
dfa5517337ed5a24db45ecba6dab5972893b5b4a
|
refs/heads/master
| 2022-12-23T11:48:09.213456
| 2020-09-22T17:38:16
| 2020-09-22T17:38:16
| 287,564,955
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,759
|
cpp
|
mainwindow.cpp
|
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QFile>
#include <QDebug>
#include "EmulatorView.h"
#include <QThread>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsScene *scene = new QGraphicsScene(this);
QTimer *timer = new QTimer();
Wheelbase *wheelbase = new Wheelbase();
emulator = new Emulator(timer, scene, wheelbase);
ui->emulatorView->initialise(scene);
ui->codeEditor->setHighlighter(&highlighter);
ui->enterButton->connect(ui->enterButton, SIGNAL (clicked()),this, SLOT (response_submitted()));
ui->nextButton->connect(ui->nextButton, SIGNAL (clicked()), this, SLOT (nextLevel()));
nextLevel();
}
MainWindow::~MainWindow()
{
delete ui;
delete emulator;
delete process;
}
void MainWindow::response_submitted() {
QString data = ui->codeEditor->toPlainText();
data += helperFunctions;
TextToFile(data);
if (!compile())
return;
process = new UserProcess();
process->connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(handle_user_output()));
process->connect(process, QOverload<int>::of(&QProcess::finished), [this](){ process->kill(); process->deleteLater(); process = nullptr; } );
}
bool MainWindow::TextToFile(QString text) {
QFile file("main.cpp");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
ui->textBrowser->append(QString("\nOpen Failed"));
return false;
}
file.write(text.toUtf8());
return true;
}
bool MainWindow::compile() {
QProcess p;
QStringList arguments = {"main.cpp"};
p.start("g++",arguments);
p.waitForFinished();
if(p.exitCode() != 0) {
ui->textBrowser->append(QString("\nCompilation Failed"));
return false;
}
ui->textBrowser->append(QString("\nCompilation Successful"));
return true;
}
void MainWindow::handle_user_output() {
QStringList output = QString(process->readAllStandardOutput()).split(QRegExp("[\n]"),QString::SkipEmptyParts);
for (int i = 0; i < output.length(); i++) {
if (output[i] == "getWheelbasePos_X()") {
process->write(QString().setNum(emulator->wheelbase->get_pos().x).toUtf8());
process->write(QString("\n").toUtf8());
}
else if (output[i] == "getWheelbasePos_Y()") {
process->write(QString().setNum(emulator->wheelbase->get_pos().y).toUtf8());
process->write(QString("\n").toUtf8());
}
else if (output[i] == "getWheelbaseVel_X()") {
process->write(QString().setNum(emulator->wheelbase ->get_real_velocity().x).toUtf8());
process->write(QString("\n").toUtf8());
}
else if (output[i] == "getWheelbaseVel_Y()") {
process->write(QString().setNum(emulator->wheelbase->get_real_velocity().y).toUtf8());
process->write(QString("\n").toUtf8());
}
else if (output[i] == "setWheelbaseVel()") {
if (output.length() < i+3) {
ui->textBrowser->append(QString("Proper Use ofSetWheelbaseVel():\ncout << SetWheelbaseVel() << endl;\ncout << float(x vel) << endl;\ncout << float(y vel) << endl;").toUtf8());
return;
}
emulator->set_user_vel(XYTheta{.x = output[i+1].toFloat(),.y = output[i+2].toFloat(),.theta = 0});
i = i+2;
}
else {
ui->textBrowser->append(output[i]);
}
}
}
void MainWindow::nextLevel() {
switch(emulator->level) {
case BEGINNER:
ui->codeEditor->setText(QString(R"~(
#include <iostream>
using namespace std;
/* Helper Functions */
/**
* @brief This function returns the current x position of the wheelbase
*/
float getWheelbasePos_X();
/**
* @brief This function returns the current y position of the wheelbase
*/
float getWheelbasePos_Y();
/**
* @brief This function returns the current x velocity of the wheelbase
*/
float getWheelbaseVel_X();
/**
* @brief This function returns the current y velocity of the wheelbase
*/
float getWheelbaseVel_Y();
/**
* @brief This function allows you to set the optimal velocity of the wheelbase
*/
void setWheelbaseVel(float x, float y);
int main() {
}
)~"));
ui->textBrowser->setText(QString("Welcome to the Omni Wheelbase Emulator\nUse the functions and try to reach the target\n"));
break;
case INTRO_TRAPEZOID:
ui->textBrowser->setText(QString(""));
break;
case INTRO_PID:
break;
case END:
break;
}
emulator->level = static_cast<LEVEL>(static_cast<int>(emulator->level)+1);
}
|
767c303f66efaa7b04e18479a87e3d9a8de9b83d
|
c09d4ca5004a4909d991a53df30739c2d3e3fb66
|
/src/gui/tool/ModifyTool.hpp
|
1a4958fd34b7f1166e7288b40c4cb6a91c6c2d8f
|
[] |
no_license
|
TricksterGuy/Morphan
|
8dbaa1831ad41374a6119052f89a0a5f6443f4e0
|
1ae5b554e76589895f6d6f680474d016ff1a803c
|
refs/heads/master
| 2020-05-05T03:15:48.474089
| 2018-10-28T20:34:10
| 2018-10-28T20:34:10
| 17,351,373
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,368
|
hpp
|
ModifyTool.hpp
|
/******************************************************************************************************
* Morphan
* Copyright (C) 2014 Brandon Whitehead (tricksterguy87[AT]gmail[DOT]com)
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* excluding commercial applications, and to alter it and redistribute it freely,
* subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* An acknowledgement in your documentation and link to the original version is required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
******************************************************************************************************/
#ifndef MODIFY_TOOL_HPP
#define MODIFY_TOOL_HPP
#include <set>
#include <vector>
#include <wx/clntdata.h>
#include <wx/dcgraph.h>
#include "Primitive.hpp"
enum class SelectionMode {ALL, FIRST};
extern wxRealPoint INVALID_POINT;
static inline bool IsValidPoint(const wxRealPoint& point)
{
return point != INVALID_POINT;
}
struct PrimitiveSelection
{
PrimitiveSelection(Primitive* nprimitive, int npoint) : primitive(nprimitive), point_id(npoint) {}
Primitive* primitive;
int point_id;
bool operator<(const PrimitiveSelection& rhs) const
{
return primitive->GetId() < rhs.primitive->GetId();
}
};
class ModifyTool : public wxClientData
{
public:
ModifyTool() {}
virtual ~ModifyTool() {}
virtual std::vector<Primitive*> Modify(const wxRealPoint& origin) = 0;
/*** Performs the main modification */
void DoModify(PrimitiveSelection& ps, const wxRealPoint& origin);
/*** Preview Modification */
std::set<PrimitiveSelection> PreviewModify(const wxRealPoint& origin);
/*** Performs the attribute modification */
void Modify(const wxColour& outline, int width, const wxColour& fill, int isfilled);
/*** Sets selection mode */
void SetSelectionMode(SelectionMode nmode) {mode = nmode;}
/*** Sets selection of primitives */
void SetSelection(const std::vector<Primitive*>& primitives, const wxRealPoint& point, bool reset = false);
/*** Selects next object in selection */
void SelectNext();
/*** Selects previous object in selection */
void SelectPrevious();
/*** Gets selection */
const std::set<PrimitiveSelection>& GetSelection() const {return selection;}
/*** Gets selected Object */
std::set<PrimitiveSelection>::iterator GetSelectedObject() const {return selected_object;}
/*** Has Selection */
bool HasSelection() const {return !selection.empty();}
/*** Clears selection */
void Clear() {selection.clear(); selected_object = selection.end();}
protected:
std::set<PrimitiveSelection> selection;
std::set<PrimitiveSelection>::iterator selected_object;
SelectionMode mode;
};
#endif
|
16e3342f372e5f4492f10b98d1add8a11b08fedd
|
34e36b5bdf7b12341b0f337ed011edb9019d0633
|
/18-exceptions/main.cpp
|
1a2b755940bf97df84336586f436ce01b5da1e91
|
[
"Unlicense",
"LicenseRef-scancode-public-domain"
] |
permissive
|
twolfson/learn-cpp-playground
|
37ec96285928bc74b38a3c9cb438f6c90d047bf0
|
5338a20f90741be4defbbddbdd975a2ecad185df
|
refs/heads/master
| 2022-12-18T07:30:47.276368
| 2020-09-25T07:12:49
| 2020-09-25T07:12:49
| 283,129,463
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 144
|
cpp
|
main.cpp
|
// Load in our dependencies
#include <exception>
#include <iostream>
using namespace std;
int main (){
throw runtime_error {"Test error"};
}
|
1a5e59cc10bd3a277f07c75e9e6479a3dd8428fe
|
81ebdbbb2d2c7481376167cf698cb40052f7b845
|
/lab/lab-3/main.cpp
|
fe5f483129eb4f46c57191c38fa043558a76bbd0
|
[] |
no_license
|
austinmajor/algorithms-and-data-structures-cpp
|
40a3a050969da90240822ffd9040f72535bb3cbb
|
a530812a120937baa7ce4294b86437d5e946e705
|
refs/heads/master
| 2022-03-29T00:43:52.935688
| 2019-12-11T02:36:23
| 2019-12-11T02:36:23
| 203,716,959
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,304
|
cpp
|
main.cpp
|
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "Car.h"
// Forward function declarations, for specific function comments see their
// implementations after main.
std::string menu();
int main()
{
std::string dataFile;
std::vector<car::Model> cars;
std::cout << "Enter the name of your data file (with extension): ";
std::cin >> dataFile;
try {
cars = car::ParseDataFile(dataFile);
} catch(const char* e) {
std::cerr << "error: " << e << std::endl;
return 1;
}
// Formatting after opening file.
std::cout << std::endl;
bool running = true;
std::string selection;
int parsedSelection;
while(running) {
std::cout << menu();
std::cin >> selection;
try {
parsedSelection = std::stoi(selection);
} catch(...) {
std::cout << "Invalid selection, try again." << std::endl << std::endl;
continue;
}
switch(parsedSelection) {
case 1: {
std::cout << std::endl;
for(car::Model c : cars) {
std::cout << car::PrintModel(c) << std::endl;
}
std::cout << std::endl;
break;
}
case 2: {
std::cout << std::endl << "Enter an ID to search by: ";
std::cin >> selection;
try {
parsedSelection = std::stoi(selection);
} catch(...) {
std::cout << "Invalid ID given, returning to menu."
<< std::endl << std::endl;
continue;
}
for(car::Model c : cars) {
if(c.id == parsedSelection) {
std::cout << car::PrintModel(c) << std::endl
<< std::endl;
break;
}
}
break;
}
case 3: {
std::cout << std::endl << "Enter a make to search by: ";
std::cin >> selection;
bool found = false;
for(car::Model c : cars) {
if(c.make == selection) {
std::cout << car::PrintModel(c) << std::endl
<< std::endl;
found = true;
}
}
if(!found) {
std::cout << "No cars found by given make, returning to menu."
<< std::endl << std::endl;
}
break;
}
case 4: {
std::cout << std::endl << "Enter a model to search by: ";
std::cin >> selection;
bool found = false;
for(car::Model c : cars) {
if(c.model == selection) {
std::cout << car::PrintModel(c) << std::endl
<< std::endl;
found = true;
}
}
if(!found) {
std::cout << "No cars found by given model, returning to menu."
<< std::endl << std::endl;
}
break;
}
case 5: {
std::cout << std::endl << "Enter a color to search by: ";
std::cin >> selection;
bool found = false;
for(car::Model c : cars) {
if(c.color == selection) {
std::cout << car::PrintModel(c) << std::endl
<< std::endl;
found = true;
}
}
if(!found) {
std::cout << "No cars found by given color, returning to menu."
<< std::endl << std::endl;
}
break;
}
case 6: {
car::Model newCar;
// Get new ID by getting the last element's ID and adding one.
newCar.id = cars.at(cars.size() - 1).id + 1;
std::cout << std::endl << "Enter the make of the car to add: ";
std::cin >> newCar.make;
std::cout << "Enter the model of the car to add: ";
std::cin >> newCar.model;
std::cout << "Enter the color of the car to add: ";
std::cin >> newCar.color;
try {
car::AddModel(dataFile, newCar);
} catch(const char* e) {
std::cout << "Error encountered adding car: "
<< e << std::endl << std::endl;
continue;
}
cars.push_back(newCar);
std::cout << std::endl << "New car succesfully added: "
<< PrintModel(newCar) << std::endl << std::endl;
break;
}
case 7: {
std::cout << std::endl << "Enter an ID to delete: ";
std::cin >> selection;
try {
parsedSelection = std::stoi(selection);
} catch(...) {
std::cout << "Invalid ID given, returning to menu."
<< std::endl << std::endl;
continue;
}
bool found = false;
for(unsigned long i = 0; i < cars.size(); i++) {
if(cars.at(i).id == parsedSelection) {
cars.erase(cars.begin()+i);
try {
car::DeleteModel(dataFile, cars.at(i).id);
std::cout << "Car (ID:"
<< parsedSelection
<< ") has been succesfully deleted."
<< std::endl << std::endl;
} catch(const char* e) {
std::cout << "Error deleting car by ID: " << e << std::endl << std::endl;
}
found = true;
break;
}
}
if(!found) {
std::cout << "No car found with the given ID."
<< std::endl << std::endl;
}
break;
}
case 8: {
running = false;
break;
}
default: {
std::cout << std::endl << "Invalid selection, try again."
<< std::endl << std::endl;
break;
}
}
}
return 0;
}
// Menu returns the string representation of the menu for the program.
std::string menu() {
std::stringstream ss;
ss << "Menu:" << std::endl << "1. List all cars" << std::endl << "2. Search by ID"
<< std::endl << "3. Search by make" << std::endl << "4. Search by model"
<< std::endl << "5. Search by color" << std::endl << "6. Add new car"
<< std::endl << "7. Delete by ID" << std::endl << "8. Exit" << std::endl
<< std::endl << "Select an operation by its numeric key: ";
return ss.str();
}
|
6c9885c9529601ff53e6bbf2f21bea3856c89de3
|
fcd145b1a12edea260d482583f88311e18b05030
|
/Codeforces/264/c.cpp
|
10824fdee9d9db7748956363d6805fa43f6f0c83
|
[] |
no_license
|
triplemzim/competitive_programming
|
f7e7cf098b19c3abbf2b3ff6bb6e237122deaaf0
|
3da9560d021b743dd55f5165c0c0bb7e9adbf828
|
refs/heads/master
| 2021-01-22T23:21:29.082154
| 2017-03-20T22:23:11
| 2017-03-20T22:23:11
| 85,630,988
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,241
|
cpp
|
c.cpp
|
#include<bits/stdc++.h>
using namespace std;
#define ms(x,val) memset(x,val,sizeof(x))
#define scan(x) scanf("%d",&x)
#define print(x) printf("debug= %d\n",x)
#define ull unsigned long long
#define iii long long
#define pi acos(-1)
#define pb push_back
#define PII pair<int,int>
#define vi vector<int>
#define MAPL map<long long, int >
#define MAPI map<int,int>
#define MAPP map< pair<int,int> , int>
#define MP make_pair
#define eps 1e-9
#define inf 999999999
#define MAXN 1000009
#define MOD 1000000007 // 10^9 + 7
iii n,chess[2001][2001];
iii fs[2001][2001],fe[2001][2001],gs[2001][2001],ge[2001][2001];
int main()
{
// freopen("in.txt","r",stdin);
scanf("%I64d",&n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%I64d",&chess[i][j]);
}
}
for (int i = 0; i < n; i++) {
ge[n-1][i]=chess[n-1][i];
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
fs[i][j]=(j-1>=0 ? fs[i-1][j-1]+chess[i-1][j-1] : 0) ;gs[i][j]= (j+1<n ? gs[i-1][j+1]+chess[i-1][j+1] :0);
}
}
for(int i=n-2;i>=0;i--)
{
for (int j = 0; j < n; j++) {
fe[i][j]=(j-1>=0? fe[i+1][j-1]+chess[i+1][j-1]: 0) ; ge[i][j]= (j+1<n? ge[i+1][j+1] : 0) +chess[i][j];
}
}
// cout<<fs[3][1]+fe[3][1]-fe[3][1]<<endl;
iii max_black=-1,max_white=-1,x,y,xx,yy,temp;
bool flag=false;
for (int i = 0; i < n; i++) {
if((n&1)==0) flag=!flag;
// cout<<endl;
for (int j = 0; j < n; j++) {
temp=fs[i][j]+fe[i][j]+gs[i][j]+ge[i][j];
// cout<<flag<<' ';
if(flag)
{
flag=false;
if(temp>max_white)
{
max_white=temp;
x=i;y=j;
}
}
else
{
flag=true;
if(temp>max_black)
{
max_black=temp;
xx=i;yy=j;
}
}
}
}
cout<<max_white+max_black<<endl;
cout<<x+1<<' '<<y+1<<' '<<xx+1<<' '<<yy+1<<endl;
return 0;
}
|
9fd4e528a8a8bea8b2b9cf9a95586918d2e77b0e
|
1fc61423f744ddd9d01dac00fd4155c5f8154c86
|
/WorldTiles.h
|
2db032ebed94ee3ef76bffba0a6ca2e938ab38e0
|
[] |
no_license
|
Almahmudrony/ArgoVox
|
a40e119d0007f67f2aea3afa012c11d3c967b859
|
b8c32f0c04c7ce8455b510eb33565acf723deb9f
|
refs/heads/master
| 2021-01-22T03:44:01.373145
| 2013-04-10T02:54:00
| 2013-04-10T02:54:00
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 771
|
h
|
WorldTiles.h
|
#ifndef WORLDTILES_H
#define WORLDTILES_H
#include <vector>
#include "Tile.h"
#include "TileManager.h"
#include "WorldChunks.h"
#include "Frustum.h"
using namespace std;
enum TileMode
{
GREEN,
RED,
YELLOW
};
class WorldTiles
{
private:
struct TileData
{
TileMode tileMode;
vector<Tile *> *tiles;
};
int m_nWidth, m_nHeight;
TileData ***m_worldTiles;
vector<Tile *> *m_allTiles;
public:
WorldTiles(int nWidth, int nHeight);
void init();
void initializeFromChunks(WorldChunks *chunks, TileManager *manager, PhysicsManager *physicsManager);
bool addTile(int nPosX, int nPosY, Tile *tile, PhysicsManager *physicsManager);
vector<Tile *> *getAllTiles();
vector<Tile *> *getVisibleTiles(Frustum *frustum);
int getWidth();
int getHeight();
};
#endif
|
fc217abc46ce9d08f1072d6e7907f98f9f4d594a
|
163d370755cdbd0675d2a95fb0c4d374cddaddbd
|
/road.cpp
|
dbff3c4e42957d10231e3cc89aa9afd85d0a4e47
|
[] |
no_license
|
AlexeyKulbitsky/Constructor
|
730bf96616cb788435e5c456db1ffb7db53928e4
|
8e3518e5a60cacbcbcc0e9b5996c07132ed989a4
|
refs/heads/master
| 2021-01-13T00:49:31.235913
| 2016-03-14T08:36:52
| 2016-03-14T08:36:52
| 36,598,299
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 10,957
|
cpp
|
road.cpp
|
#include "road.h"
#include <math.h>
#include <QtGui>
Road::Road()
{
setVertexArray(0.0, 0.0, 1.0);
setColorArray(0.5f, 0.5f, 0.5f, 1.0f);
setIndexArray();
// Рaмка для выбора фигуры
setIndexArrayForSelectionFrame();
setColorArrayForSelectionFrame(0.0f, 0.0f, 0.0f);
selected = false;
getTextures();
fixed = false;
}
Road::Road(float x, float y, float size)
{
this->size = size;
this->red = 0.5f;
this->green = 0.5f;
this->blue = 0.5f;
this->alpha = 1.0f;
setVertexArray(x, y, size);
setColorArray(0.5f, 0.5f, 0.5f, 1.0f);
setIndexArray();
setIndexArrayForSelectionFrame();
setColorArrayForSelectionFrame(0.0f, 0.0f, 0.0f);
selected = false;
getTextures();
fixed = false;
}
Road::Road(float x, float y, float size, float red, float green, float blue, float alpha)
{
this->size = size;
this->red = red;
this->green = green;
this->blue = blue;
this->alpha = alpha;
setVertexArray(x, y, size);
setColorArray(red, green, blue, alpha);
setIndexArray();
setIndexArrayForSelectionFrame();
setColorArrayForSelectionFrame(0.0f, 0.0f, 0.0f);
selected = false;
getTextures();
fixed = false;
}
Road::~Road()
{
}
// Индексы вершины для отрисовки
void Road::setVertexArray(float x, float y, float size)
{
this->getTextures();
VertexArray[0][0]=x-size;
VertexArray[0][1]=y-size;
VertexArray[0][2]=0.01f;
TextureArray[0][0] = 0.0f;
TextureArray[0][1] = 0.0f;
VertexArray[1][0]=x-size;
VertexArray[1][1]=y+size;
VertexArray[1][2]=0.01f;
TextureArray[1][0] = 0.0f;
TextureArray[1][1] = 1.0f;
VertexArray[2][0]=x+size;
VertexArray[2][1]=y+size;
VertexArray[2][2]=0.01f;
TextureArray[2][0] = 1.0f;
TextureArray[2][1] = 1.0f;
VertexArray[3][0]=x+size;
VertexArray[3][1]=y-size;
VertexArray[3][2]=0.01f;
TextureArray[3][0] = 1.0f;
TextureArray[3][1] = 0.0f;
}
// Индексы каждой вершины
void Road::setColorArray(float red, float green, float blue, float alpha)
{
for (int i=0; i<4; i++)
{
ColorArray[i][0]=red;
ColorArray[i][1]=green;
ColorArray[i][2]=blue;
ColorArray[i][3]=alpha;
}
}
// Индексы для отрисовки фигуры
void Road::setIndexArray()
{
// Порядок обхода - по часовой стрелке
// 1-ый полигон
IndexArray[0][0]=0;
IndexArray[0][1]=2;
IndexArray[0][2]=1;
// 2-ой полигон
IndexArray[1][0]=0;
IndexArray[1][1]=3;
IndexArray[1][2]=2;
}
void Road::drawFigure(QGLWidget* render)
{
if (selected == true)
{
if (indexOfSelectedControl >= 0)
{
//glLineWidth(2.0);
//glPointSize(5.0);
// drawControlElement(indexOfSelectedControl, 2.0, 5.0);
}
// Если фигуры выбрана - изменяем цвет заливки
setColorArray(0.7f, 0.7f, 0.7f, alpha);
drawSelectionFrame();
}
else
{
// Если фигуры не выбрана - цвет заливки по умолчанию
setColorArray(red, green, blue, alpha);
}
glDisableClientState(GL_COLOR_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, textureID[0]);
glVertexPointer(3, GL_FLOAT, 0, VertexArray);
//glColorPointer(4, GL_FLOAT, 0, ColorArray);
glTexCoordPointer(2, GL_FLOAT, 0, TextureArray);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, IndexArray);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
}
void Road::setIndexArrayForSelectionFrame()
{
IndexArrayForSelection[0] = 0;
IndexArrayForSelection[1] = 1;
IndexArrayForSelection[2] = 2;
IndexArrayForSelection[3] = 3;
}
void Road::setColorArrayForSelectionFrame(float red, float green, float blue)
{
for (int i = 0; i < 4; ++i)
{
ColorArrayForSelection[i][0] = red;
ColorArrayForSelection[i][1] = green;
ColorArrayForSelection[i][2] = blue;
}
}
void Road::drawSelectionFrame()
{
// Боковые грани для изменения размера
glVertexPointer(3, GL_FLOAT, 0, VertexArray);
glColorPointer(3, GL_FLOAT, 0, ColorArrayForSelection);
glLineWidth(2.0);
glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_BYTE, IndexArrayForSelection);
// Угловые точки для изменения размера
glPointSize(7.0);
glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, IndexArrayForSelection);
}
void Road::move(float dx, float dy, float dz)
{
if (fixed)
{
return;
}
for (int i = 0; i < 4; ++i)
{
VertexArray[i][0] += dx; // X
VertexArray[i][1] += dy; // Y
}
}
void Road::drawControlElement(int index, float lineWidth, float pointSize)
{
// Рисуем первые 4 точки для изменения размера
if (index < 4)
{
glPointSize(pointSize);
glBegin(GL_POINTS);
glColor3d(1.0, 1.0, 0.1);
glVertex3d(VertexArray[index][0],
VertexArray[index][1],
VertexArray[index][2]);
glEnd();
}
else
{
if (index < 7)
{
glLineWidth(lineWidth);
glBegin(GL_LINES);
glColor3d(1.0, 1.0, 0.1);
glVertex3d(VertexArray[index - 4][0],
VertexArray[index - 4][1],
VertexArray[index - 4][2]);
glColor3d(1.0, 1.0, 0.1);
glVertex3d(VertexArray[index - 3][0],
VertexArray[index - 3][1],
VertexArray[index - 3][2]);
glEnd();
}
else
{
if (index == 7)
{
glLineWidth(lineWidth);
glBegin(GL_LINES);
glColor3d(1.0, 1.0, 0.1);
glVertex3d(VertexArray[index - 4][0],
VertexArray[index - 4][1],
VertexArray[index - 4][2]);
glColor3d(1.0, 1.0, 0.1);
glVertex3d(VertexArray[0][0],
VertexArray[0][1],
VertexArray[0][2]);
glEnd();
}
}
}
}
void Road::resizeByControl(int index, float dx, float dy, float x, float y)
{
if (fixed)
{
return;
}
switch (index)
{
case 0:
VertexArray[0][0] += dx;
VertexArray[0][1] += dy;
// VertexArray[1][0] += dx;
// VertexArray[3][1] += dy;
break;
case 1:
VertexArray[1][0] += dx;
VertexArray[1][1] += dy;
// VertexArray[0][0] += dx;
// VertexArray[2][1] += dy;
break;
case 2:
VertexArray[2][0] += dx;
VertexArray[2][1] += dy;
// VertexArray[3][0] += dx;
// VertexArray[1][1] += dy;
break;
case 3:
VertexArray[3][0] += dx;
VertexArray[3][1] += dy;
// VertexArray[2][0] += dx;
// VertexArray[0][1] += dy;
break;
case 4:
VertexArray[0][0] += dx;
VertexArray[1][0] += dx;
break;
case 5:
VertexArray[1][1] += dy;
VertexArray[2][1] += dy;
break;
case 6:
VertexArray[2][0] += dx;
VertexArray[3][0] += dx;
break;
case 7:
VertexArray[3][1] += dy;
VertexArray[0][1] += dy;
break;
default:
break;
}
}
void Road::changeColorOfSelectedControl(int index)
{
indexOfSelectedControl = index;
//qDebug() << "ROAD CONTROL COLOR CHANGED";
}
QCursor Road::getCursorForControlElement(int index)
{
switch (index)
{
// Углы для изменения размера
case 0:
return Qt::CrossCursor;
case 1:
return Qt::CrossCursor;
case 2:
return Qt::CrossCursor;
case 3:
return Qt::CrossCursor;
// Стороны для изменения размера
case 4:
return Qt::SizeHorCursor;
case 5:
return Qt::SizeVerCursor;
case 6:
return Qt::SizeHorCursor;
case 7:
return Qt::SizeVerCursor;
default:
return Qt::ArrowCursor;
}
}
bool Road::hasPoint(GLfloat x, GLfloat y)
{
if (x >= VertexArray[0][0] &&
x <= VertexArray[2][0] &&
y >= VertexArray[0][1] &&
y <= VertexArray[2][1])
{
return true;
}
else
{
return false;
}
}
QPoint Road::getCoorninateOfPointControl(int index)
{
QPoint p;
p.setX(VertexArray[index][0]);
p.setY(VertexArray[index][1]);
return p;
}
void Road::getTextures()
{
QImage image1;
image1.load("D://texture.png");
image1 = QGLWidget::convertToGLFormat(image1);
glGenTextures(1, textureID);
// создаём и связываем 1-ый текстурный объект с последующим состоянием текстуры
glBindTexture(GL_TEXTURE_2D, textureID[0]);
// связываем текстурный объект с изображением
glTexImage2D(GL_TEXTURE_2D, 0, 4, (GLsizei)image1.width(), (GLsizei)image1.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image1.bits());
// задаём линейную фильтрацию вблизи:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// задаём линейную фильтрацию вдали:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// задаём: при фильтрации игнорируются тексели, выходящие за границу текстуры для s координаты
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// задаём: при фильтрации игнорируются тексели, выходящие за границу текстуры для t координаты
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// задаём: цвет текселя полностью замещает цвет фрагмента фигуры
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
void Road::getProperties(QFormLayout *layout, QGLWidget* render)
{
while(QLayoutItem* child = layout->takeAt(0))
{
delete child->widget();
delete child;
}
}
bool Road::isFixed()
{
return fixed;
}
void Road::drawMeasurements(QGLWidget *render)
{
}
bool Road::setFixed(bool fixed)
{
this->fixed = fixed;
return true;
}
int Road::getLayer()
{
return layer;
}
void Road::clear()
{
}
|
5e1317b48b34618f49024e3579aa09c4b340fb81
|
927c92708e1967b8ed079fee75dacc6954c30804
|
/Vec3/Vec3 exercice/Class.h
|
9658a1815e1b4999e269ea447e7c2df45d63bb94
|
[] |
no_license
|
Sersius/Development
|
f704712c9f48c5faa390bbf05674ca85db4a739a
|
4a94b16841dc659d2471b91207a61a65487290c4
|
refs/heads/master
| 2020-03-28T19:24:56.452857
| 2018-10-04T20:38:38
| 2018-10-04T20:38:38
| 148,974,132
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,592
|
h
|
Class.h
|
#ifndef _VEC3_
#define _VEC3_
#include <math.h>
template <class TYPE>
//class string
//string a;
//string b("Hello!");
//string c(b);
//a = "bye";
class Vec3
{
public:
Vec3();
Vec3(TYPE x, TYPE y, TYPE z);
Vec3(TYPE a);
~Vec3();
Vec3 operator+ (const Vec3 &vec)const;
Vec3 operator- (const Vec3 &vec)const;
Vec3 operator+= (const Vec3 &vec);
Vec3 operator-= (const Vec3 &vec);
Vec3 operator= (const Vec3 &vec);
bool operator== (const Vec3 &vec)const;
void normalize()const;
void zero()const;
bool is_zero()const;
float distance_to(const Vec3 &vec)const;
TYPE distance_squared(const Vec3 &vec)const;
TYPE x, y, z;
};
template <class TYPE>
Vec3<TYPE>::Vec3() {}
template <class TYPE>
Vec3<TYPE>::Vec3(TYPE x, TYPE y, TYPE z) : x(x), y(y), z(z) {}
template <class TYPE>
Vec3<TYPE>::Vec3(TYPE a) : z(a), y(a), z(a) {}
template <class TYPE>
Vec3<TYPE>::~Vec3() {}
template <class TYPE>
Vec3<TYPE> Vec3<TYPE>::operator+(const Vec3 &vec)const
{
return Vec3<TYPE>(this->x + vec.x, this->y + vec.y, this->z + vec.z);
}
template <class TYPE>
Vec3<TYPE> Vec3<TYPE>::operator-(const Vec3 &vec)const
{
return Vec3<TYPE>(this->x - vec.x, this->y - vec.y, this->z - vec.z);
}
template <class TYPE>
Vec3<TYPE> Vec3<TYPE>::operator+= (const Vec3 &vec)
{
return (this->x + vec.x, this->y + vec.y, this->z + vec.z);
}
template <class TYPE>
Vec3<TYPE> Vec3<TYPE>::operator-= (const Vec3 &vec)
{
return (this->x - vec.x, this->y - vec.y, this->z - vec.z);
}
template <class TYPE>
Vec3<TYPE> Vec3<TYPE>::operator= (const Vec3 &vec)
{
return (this->x = vec.x, this->y = vec.y, this->z = vec.z);
}
template <class TYPE>
bool Vec3<TYPE>::operator== (const Vec3 &vec)const
{
return (this->x == vec.x, this->y == vec.y, this->z == vec.z);
}
template <class TYPE>
void Vec3<TYPE>::normalize()const
{
TYPE module = (sqrt(x * x + y * y + z * z));
Vec3<TYPE>(x / module, y / module, z / module);
}
template <class TYPE>
void Vec3<TYPE>::zero()const
{
Vec3<TYPE>(this->x = 0.0f, this->y = 0.0f, this->z = 0.0f);
}
template <class TYPE>
bool Vec3<TYPE>::is_zero()const
{
return Vec3<TYPE>(this->x == 0.0f, this->y == 0.0f, this->z == 0.0f);
}
template <class TYPE>
float Vec3<TYPE>::distance_to(const Vec3 &vec)const
{
TYPE distance = sqrt(((x - vec.x) * (x - vec.x)) + ((y - vec.y) * (y - vec.y)) + ((z - vec.z) * (z - vec.z)));
return distance;
}
template <class TYPE>
TYPE Vec3<TYPE>::distance_squared(const Vec3 &vec)const
{
TYPE distance_squared = ((x - vec.x) * (x - vec.x)) + ((y - vec.y) * (y - vec.y)) + ((z - vec.z) * (z - vec.z));
return distance_squared;
}
#endif
|
003704c429eb52e6747856d9b8391641a4ccdf99
|
be3c5f574c1d09c3a68d3d93f37e5a6d0acee075
|
/jungol/128/JOL128_반복제어문.cpp
|
488303c1bd8af8f4839f0fc1573327f25e187a31
|
[] |
no_license
|
azvfsxcd/Algo
|
fc15af7c4cdfd9e40e39acff9938400f20e770bc
|
e2cad9c32a723e0d2b3c7457e663bde50acc436b
|
refs/heads/master
| 2023-08-19T08:02:10.122601
| 2021-10-10T12:48:12
| 2021-10-10T12:48:12
| 388,037,652
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 294
|
cpp
|
JOL128_반복제어문.cpp
|
#include <iostream>
using namespace std;
int main()
{
int a = 1;
int cnt = 0;
while (a != 0)
{
cin >> a;
if (a == 0)
{
break;
}
if (a % 3 != 0 && a % 5 != 0)
{
cnt += 1;
}
}
cout << cnt;
}
|
0c6bab7b16412ee9dcffa4e9cfca6521f931da20
|
ad9aa7698a91baae91f54e3b837d205b90312037
|
/HashTable.cpp
|
28314365d67588bb4b52a0960165297744089f54
|
[] |
no_license
|
shagal239/HashTable
|
5cc29af63365a4bc0a2a1610560622f821565238
|
b0246d63b1c9c8812da2109b82d554df6a8ecf57
|
refs/heads/master
| 2021-01-22T15:23:28.818429
| 2015-06-08T09:51:23
| 2015-06-08T09:51:23
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,944
|
cpp
|
HashTable.cpp
|
//
// HashTable.cpp
// test
//
// Created by Guest User on 25/05/15.
// Copyright (c) 2015 Guest User. All rights reserved.
//
#include "HashTable.h"
unsigned long HashTable::HashFunction(const string &str)
{
//Rs
static const unsigned long b = 378551;
unsigned long a = 63689;
unsigned long hash = 0;
for (unsigned int i = 0; i < str.length(); i++)
{
hash = hash * a + (unsigned char)str[i];
a *= b;
}
return hash % size;
}
void HashTable::ClearList(HashList *list)
{
if (list->next) ClearList(list->next);
delete list;
}
void HashTable::RemapList(HashList *list)
{
if (list->next) RemapList(list->next);
Add(list->key, list->value);
delete list;
}
void HashTable::ResizeArray(void)
{
vector<HashList*> *old_array = hash_array;
hash_array = new vector<HashList*>(size*=2);
for (unsigned long i = 0; i < size >> 1; i++)
{
if ((*old_array)[i]) RemapList((*old_array)[i]);
}
delete old_array;
}
HashTable::HashTable()
{
size = 256;
hash_array = new vector<HashList*>(size);
resizing = resize = false;
}
HashTable::HashTable(const unsigned long size)
{
this->size = size;
hash_array = new vector<HashList*>(size);
resizing = resize = false;
}
HashTable::~HashTable()
{
for (unsigned long i = 0; i < size; i++)
{
if ((*hash_array)[i]) ClearList((*hash_array)[i]);
}
}
bool HashTable::Add(const string &key, const string &value)
{
HashList *new_value = new HashList();
new_value -> key = key;
new_value -> value = value;
new_value -> next = NULL;
HashList *last_value;
if ((last_value = (*hash_array)[HashFunction(key)]))
{
int count = 1;
for (;;++count)
{
if (last_value->key == key)
{
delete new_value;
return false;
}
if (last_value->next) last_value = last_value->next;
else break;
}
last_value->next = new_value;
if (count > 4)
{
if (resizing) resize = true;
else
{
do
{
resize = false;
resizing = true;
ResizeArray();
resizing = false;
} while (resize);
}
}
}
else (*hash_array)[HashFunction(key)] = new_value;
return true;
}
string* HashTable::Search(const string &key)
{
HashList *current_value = (*hash_array)[HashFunction(key)];
if (current_value)
for (;;)
{
if (current_value->key == key) return ¤t_value->value;
if (current_value->next) current_value = current_value->next;
else break;
}
return NULL;
}
bool HashTable::Delete(const string &key)
{
HashList *current_value = (*hash_array)[HashFunction(key)];
HashList *last_value = current_value;
if (current_value)
for (;;)
{
if (current_value->key == key)
{
if (last_value == current_value) (*hash_array)[HashFunction(key)] = current_value->next;
else last_value->next = current_value->next;
delete current_value;
return true;
}
if (current_value->next)
{
last_value = current_value;
current_value = current_value->next;
}
else break;
}
return false;
}
|
3eb12cffacf7abd5aa8463fe0370ba11a6300108
|
6b2a8dd202fdce77c971c412717e305e1caaac51
|
/solutions_2751486_0/C++/Opportunit/1.cpp
|
ca10b98fae370d711ebf7fc7b5fc9d316d226f79
|
[] |
no_license
|
alexandraback/datacollection
|
0bc67a9ace00abbc843f4912562f3a064992e0e9
|
076a7bc7693f3abf07bfdbdac838cb4ef65ccfcf
|
refs/heads/master
| 2021-01-24T18:27:24.417992
| 2017-05-23T09:23:38
| 2017-05-23T09:23:38
| 84,313,442
| 2
| 4
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 607
|
cpp
|
1.cpp
|
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
ifstream fi("1.in");
ofstream fo("1.out");
int nr,rs,tt,t,n,i,j,k,a[1000],ok;
string s;
int main(){
fi >> t;
for (tt=1; tt<=t; tt++){
fi >> s >> n;
rs=0;
for (i=n; i<=(int)s.size(); i++){
for (j=0; j<=(int)s.size()-i; j++){
nr=0,ok=0;
for (k=j; k<=j+i-1; k++){
if (s[k]=='a'||s[k]=='e'||s[k]=='i'||s[k]=='o'||s[k]=='u') nr=0; else nr++;
if (nr>=n) ok=1;
}
if (ok) rs++;
}
}
fo << "Case #" << tt << ": " << rs << endl;
}
return 0;
}
|
1f0dc387a04258d92aea47721702b40c7c841337
|
5e3e237a56527656dc6ea2b1e8e0a52b559a604d
|
/Pangolin-master/include/pangolin/image/image.h
|
630f2e4d2644c181720f1a3debfb0fdaa38de5fa
|
[
"MIT"
] |
permissive
|
hyperci-support/hpslam_SDK
|
8085725d64093d3a088d4c2e43b8c81a64e9283d
|
8d66b94949508245503e2905200db2722e6e58e0
|
refs/heads/master
| 2021-01-22T03:33:29.801890
| 2017-06-16T07:01:35
| 2017-06-16T07:01:35
| 92,387,647
| 5
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,402
|
h
|
image.h
|
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef PANGOLIN_IMAGE_H
#define PANGOLIN_IMAGE_H
#include <cstddef>
namespace pangolin
{
// Simple image wrapper
template<typename T>
struct Image {
inline Image()
: pitch(0), ptr(0), w(0), h(0)
{
}
inline Image(size_t w, size_t h, size_t pitch, T* ptr)
: pitch(pitch), ptr(ptr), w(w), h(h)
{
}
void Dealloc()
{
if(ptr) {
::operator delete(ptr);
ptr = NULL;
}
}
void Alloc(size_t w, size_t h, size_t pitch)
{
Dealloc();
this->w = w;
this->h = h;
this->pitch = pitch;
this->ptr = (T*)::operator new(h*pitch);
}
size_t SizeBytes() const
{
return pitch * h;
}
size_t Area() const
{
return w * h;
}
template<typename To>
Image<To> Reinterpret() const
{
return Image<To>(w,h,pitch, (To*)ptr);
}
T* RowPtr(int r)
{
return (T*)((char*)ptr + r*pitch);
}
const T* RowPtr(int r) const
{
return (T*)((char*)ptr + r*pitch);
}
size_t pitch;
T* ptr;
size_t w;
size_t h;
};
}
#endif // PANGOLIN_IMAGE_H
|
60d4d68fc5a7081a8406d348f6cdc40faa40f650
|
c8d8d5335803d36549cafd55bb7c691e0bcf51fb
|
/2do-cuatrimestre/ejercicios/listas/ej2/ej2/main.cpp
|
0c917d4a0662f2514f8d58e326548390605aac84
|
[] |
no_license
|
NicoAcosta/utn-ayed
|
fb7b7f9a065b37b40fac543f3cc2d09ac9362917
|
d38dc7e64e4e8aed837dfdd4e191f950b8b4c925
|
refs/heads/main
| 2023-02-19T01:03:01.808002
| 2021-01-19T22:24:08
| 2021-01-19T22:24:08
| 306,265,257
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,639
|
cpp
|
main.cpp
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
struct Nodo {
int info;
Nodo *sgte;
};
Nodo *aux;
void crearyLLenarLista(Nodo *lista, int n) {
aux = lista;
aux->info = (2 * n) - 7;
aux->sgte = NULL;
aux->sgte = new Nodo();
aux = aux->sgte;
aux->info = (9 * n) - 7;
aux->sgte = NULL;
aux->sgte = new Nodo();
aux = aux->sgte;
aux->info = (n * 5) - 7;
aux->sgte = NULL;
aux->sgte = new Nodo();
aux = aux->sgte;
aux->info = (5 * n) - 7;
aux->sgte = NULL;
aux->sgte = new Nodo();
aux = aux->sgte;
aux->info = (1 * n) - 7;
aux->sgte = NULL;
aux->sgte = new Nodo();
aux = aux->sgte;
aux->info = (6 * n) - 7;
aux->sgte = NULL;
}
int cantNodos(Nodo *lista) {
int i = 0;
Nodo *auxcant = new Nodo();
auxcant = lista;
while (auxcant) {
i++;
auxcant = auxcant->sgte;
}
return i;
}
void mostrarLista(Nodo *lista) {
aux = lista;
while (aux) {
cout << aux->info << endl;
aux = aux->sgte;
}
cout << endl;
}
Nodo *ultimo(Nodo *lista){
aux = lista;
while (aux && aux->sgte) {
aux = aux->sgte;
}
return aux;
}
void insertarAlfinal(Nodo *lista, Nodo *nuevo){
ultimo(lista)->sgte = nuevo;
}
int main() {
Nodo *l1 = new Nodo();
Nodo *l2 = new Nodo();
Nodo *l3 = new Nodo();
crearyLLenarLista(l1, 3);
crearyLLenarLista(l2, 2);
mostrarLista(l1);
mostrarLista(l2);
insertarAlfinal(l1, l2);
mostrarLista(l1);
}
|
f33a692eb1d1937c71a175ed7d968817dd0458f8
|
19999e0f98e2077e8207e54350fb701a5a04c22e
|
/Stats/StatsTest2.cxx
|
aff0a231a0f0b66deb1cc59e3f331512b5804b23
|
[
"MIT"
] |
permissive
|
wangjiaqingll/UMICH-Physical-Design-Tools
|
e9e26977554e585e181be6394f6b2428ac9105d1
|
fa0d990fc9def762e3a2843707a7d8a4784d2f8b
|
refs/heads/master
| 2022-11-13T11:05:36.106620
| 2020-07-13T06:35:26
| 2020-07-13T06:35:26
| 277,409,848
| 1
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,566
|
cxx
|
StatsTest2.cxx
|
/**************************************************************************
***
*** Copyright (c) 1995-2000 Regents of the University of California,
*** Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
*** Copyright (c) 2000-2002 Regents of the University of Michigan,
*** Saurabh N. Adya and Igor L. Markov
***
*** Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
*** Original Affiliation: UCLA, Computer Science Department,
*** Los Angeles, CA 90095-1596 USA
***
*** Permission is hereby granted, free of charge, to any person obtaining
*** a copy of this software and associated documentation files (the
*** "Software"), to deal in the Software without restriction, including
*** without limitation
*** the rights to use, copy, modify, merge, publish, distribute, sublicense,
*** and/or sell copies of the Software, and to permit persons to whom the
*** Software is furnished to do so, subject to the following conditions:
***
*** The above copyright notice and this permission notice shall be included
*** in all copies or substantial portions of the Software.
***
*** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
*** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
*** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
*** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
*** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***
***
***************************************************************************/
#include <iostream>
#include "ABKCommon/abkcommon.h"
#include "stats.h"
int main(int argc, char *argv[])
{
(void)argc;(void)argv;
double ar[]={1.2,4.1,9.1,13.1,2.1,4.2,9.2,13.2};
vector<double> dataSet1(3,Pi);
vector<double> dataSet2(6);
vector<double> dataSet3(8);
//iota(dataSet2.begin(),dataSet2.end(),0);
{for(unsigned i=0;i<dataSet2.size(); i++) dataSet2[i]=i;}
std::copy(ar,ar+8,dataSet3.begin());
cout << "=== Distribution 1 ========= " << endl << FreqDistr(dataSet1)
<< "=== Distribution 2 ========= " << endl << FreqDistr(dataSet2)
<< "=== Distribution 3 ========= " << endl
<< FreqDistr(dataSet2,10,FreqDistr::Magnitudes);
FreqDistr distr4(dataSet3);
distr4.numSubranges=4;
cout << "=== Distribution 4 ========= " << endl << distr4;
return 0;
}
|
e6aeb93394f6f3cdc8419cd19aa4ae01980186bf
|
b130597521e538d2dbf6d591e5e9343c1af97c2c
|
/VernamCipher.h
|
f7e8f9373a4c1c31443f131d78655473761d9e52
|
[] |
no_license
|
momikenSneg/Vernam-cipher
|
f537fbfec9fdb8ff80ba1fa6a652a2bec424f220
|
30a1333bc699164a451c1e044f1e0ea80a84fd0c
|
refs/heads/master
| 2020-09-30T02:57:34.409779
| 2019-12-10T18:11:46
| 2019-12-10T18:11:46
| 227,185,284
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 526
|
h
|
VernamCipher.h
|
//
// Created by momik on 27.11.2019.
//
#ifndef VERNAMCIPHER_VERNAMCIPHER_H
#define VERNAMCIPHER_VERNAMCIPHER_H
#include <string>
#include <fstream>
#include <time.h>
class VernamCipher{
private:
static const int BUF_SIZE = 100;
static char *vernamCipher(const char* key, const char *buffer, int length);
static char *generatingKey(int len);
public:
static void encrypt(const std::string& pathName);
static void decrypt(const std::string&, const std::string&);
};
#endif //VERNAMCIPHER_VERNAMCIPHER_H
|
58d9961f4e10f58a961f5bc794ff70a4cd25d901
|
3f46d6c42fef7177b80d4b89d4d185a1d9abc204
|
/Audio Programming Coursework/IXACore.hpp
|
4143d708a29b8fefe888d0bcc90339c5fa5ef02e
|
[] |
no_license
|
maverickkenmore/Code-Examples-Snippets
|
ea460c5cdd6700dcdd5b76c4629d3cd11bbf725e
|
a84556bf8c4bc403a39d3bdd3176800a8b967a1d
|
refs/heads/master
| 2021-08-30T16:00:18.761657
| 2017-12-18T14:48:58
| 2017-12-18T14:48:58
| 114,650,305
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,559
|
hpp
|
IXACore.hpp
|
/*
file: IXACore.hpp
Version: 2.2
Date: June 2013; April 2013; September 2012.
Authors: Stuart and Allan Milne.
Namespace: AllanMilne::Audio
Exposes: IXACore.
Description:
this is a design for the XACore class that will encapsulate core XAudio2 functionality
related to the XAudio2 processing engine, mastering voice and X3DAudio.
The design is presented as an interface (abstract class - pure virtual functions) defining only behaviour.
* See the XACore class for implementation details.
this version
* utilises a singleton design pattern;
* creates the XAudio2 engin, mastering voice and X3DAudio handle;
* exposes status information;
* exposes relevant get and set behaviour;
* exposes a function for calculating and applying 3D audio DSP settings to a voice.
Note that the static members implementing the singleton pattern cannot be defined in this abstract class;
these are defined in the concrete XACore class.
*/
#ifndef __IXACORE_HPP__
#define __IXACORE_HPP__
// system includes.
#include <XAudio2.h>
#include <X3DAudio.h>
namespace AllanMilne {
namespace Audio {
class IXACore
{
public:
//--- The status enumeration type.
enum Status {
Undefined, OK, EngineError, MasterError
};
//--- Virtual destructor allows correct operation of cascaded destructors.
virtual ~IXACore(){}
//--- Access to the XAudio2 engine, mastering voice and 3D handle; return NULL if errors.
virtual IXAudio2* GetEngine () const = 0;
virtual IXAudio2MasteringVoice* GetMasterVoice () const = 0;
virtual const X3DAUDIO_HANDLE& Get3DHandle () const = 0;
//--- Accessors for other global/device attributes.
virtual int GetChannelCount () const =0;
virtual const XAUDIO2_DEVICE_DETAILS& GetDeviceDetails () = 0;
virtual void Apply3D (IXAudio2SourceVoice* aVoice, const X3DAUDIO_EMITTER* anEmitter, const X3DAUDIO_LISTENER* aListener, const unsigned int flags) const = 0;
}; // end IXACore interface.
} // end Audio namespace.
} // end AllanMilne namespace.
/*
=== Version 2 Changes.
Adopts a singleton design pattern.
Protected fields are changed to private.
Adds a virtual destructor.
Removes the factory method for creating a XASound object.
Exposes explicit status information.
incorporates X3DAudio functionality:
- X3DAudio handle;
- wrapping a listener;
- exposing a function for calculating and applying 3D audio DSP settings.
---- 11/6/13 changes
Removed listener entries from interface, it is now client responsibility to manage listener
and supply XAudio2 listener type to Apply3D methods exposed by core.
*/
#endif
|
ff19c2f402d9879f38e7ad63946d8c144db91a99
|
9c2b414958938df18b258dbec6c8baef5d5af23a
|
/common/macros.h
|
433fc792ca3635e133d12d7d71cd9272346acec5
|
[] |
no_license
|
briancbecker/eyeslam
|
30df8b707897b60b30480db09a5a158916e5263a
|
98f6d2e8527b6356e9cf5ffbd03b64d911c7e040
|
refs/heads/master
| 2021-01-22T02:17:44.297665
| 2017-05-25T02:37:04
| 2017-05-25T02:37:04
| 92,350,213
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 14,712
|
h
|
macros.h
|
/*==================================================================================
Filename: macros.h
Copyright 2007 Brian C. Becker
Robotics Laboratory
University of Central Florida
http://robotics.ucf.edu
Program Contents:
-------------------------------------------------------------------------------
File containing useful macros, inline functions, and defines. Examples
include:
PI
HALF_PI
DEG2RAD
GET_TIME_MS
SLEEP
-------------------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
==================================================================================*/
#ifndef _MACROS_H
#define _MACROS_H
#include <stdio.h>
#include <time.h>
#ifdef WIN32
//#include <WinSock2.h>
#include <windows.h>
#else
#include <unistd.h>
#include <sys/time.h>
#include <string.h>
#include <locale>
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Resizes an array, moving the elements in the old array to the new one
///
/// \param mem Pointer to memory to resize
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void NEWMEM(T *&mem)
{
if (!mem)
mem = new T;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Copies one array to another
///
/// \param mem Pointer to memory to copy to
/// \param memOrig Pointer to memory to copy from
/// \param size Size of the original array
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void COPY_MEM(T *&mem, const T *memOrig, int size)
{
if (size > 0 && memOrig)
{
DELMEMS(mem);
mem = new T[size];
for (int i = 0; i < size; i++)
{
mem[i] = memOrig[i];
}
}
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Copies one array to another
///
/// \param mem Pointer to memory to copy to
/// \param memOrig Pointer to memory to copy from
/// \param delSize How much to delete from the old array
/// \param size Size of the original array
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void COPY_MEM(T *&mem, const T *memOrig, int &delSize, int size)
{
if (delSize > 0 && size > 0 && memOrig)
{
DELMEMS(mem, delSize);
mem = new T[delSize = size];
for (int i = 0; i < size; i++)
{
mem[i] = memOrig[i];
}
}
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Resizes an array, moving the elements in the old array to the new one
///
/// \param mem Pointer to memory to resize
/// \param oldsize Existing size of the array
/// \param newsize New size of the array (-1 indicates increase to 2*oldsize)
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void RESIZE_MEM(T *&mem, int &oldsize, int newsize = -1)
{
if (oldsize == 0 || mem == 0)
{
DELMEMS(mem);
if (newsize <= 0) newsize = 1;
mem = new T[newsize];
return;
}
if (newsize == -1) newsize = oldsize*2;
if (newsize <= 0) newsize = 1;
T *nmem = new T[newsize];
for (int i = 0; i < oldsize; i++)
{
nmem[i] = mem[i];
}
DELMEMS(mem);
mem = nmem;
// If we want, we can reset the size
// oldsize = newsize;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Deletes a memory spot and sets it to zero
///
/// \param mem Pointer to memory to delete. To delete an array, call DELMEMS
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void DELMEM(T *&mem)
{
if (mem)
delete mem;
mem = 0;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Deletes a memory spot array and sets it to zero
///
/// \param mem Pointer to straight array to delete.
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void DELMEMS(T *&mem)
{
if (mem)
delete[] mem;
mem = 0;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Copies one string to another, allocating memory for the first string
///
/// \param mem Pointer to string to copy to
/// \param memOrig Pointer to string to copy from
/// \return The string that was made from the copy
///
////////////////////////////////////////////////////////////////////////////////////
inline char* COPY_STR(char *&mem, const char *memOrig)
{
DELMEMS(mem);
if (memOrig)
{
mem = new char[strlen(memOrig) + 1];
strcpy(mem, memOrig);
}
return mem;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Copies one string and returns a pointer, allocating memory
///
/// \param memOrig Pointer to string to copy from
/// \return Pointer to the newly allocated string
///
////////////////////////////////////////////////////////////////////////////////////
inline char* COPY_STR(const char *memOrig)
{
char *mem = 0;
if (memOrig)
{
mem = new char[strlen(memOrig) + 1];
strcpy(mem, memOrig);
}
else
{
mem = new char[1];
strcpy(mem, "");
}
return mem;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Deletes contents of a memory, memory array, and sets it to zero
///
/// \param mems Pointer to memory array to delete.
/// \param count Number of elements in the array
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void DELMEMS(T **&mems, int count)
{
if (mems)
{
for (int i = 0; i < count; i++)
{
if (mems[i])
delete mems[i];
}
delete[] mems;
}
mems = 0;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Cross platform system sleep call in ms.
///
/// \param ms Time to sleep in milliseconds
///
////////////////////////////////////////////////////////////////////////////////////
inline void SLEEP(int ms)
{
#if defined(WIN32)
Sleep((ms));
#else
usleep((ms*1000));
#endif
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Gets the current system time in milliseconds
///
/// \return Current time in milliseconds
///
////////////////////////////////////////////////////////////////////////////////////
inline unsigned int GET_TIME_MS(void)
{
unsigned int ms;
#ifdef WIN32
SYSTEMTIME t;
GetSystemTime(&t);
// Add up and convert to milliseconds
ms = t.wHour*3600000 + t.wMinute*60000 + t.wSecond*1000 + t.wMilliseconds;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
ms = (unsigned int)(tv.tv_sec*1000 + tv.tv_usec*1000);
#endif
return ms;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \def PI
/// \brief The value of pi.
///
////////////////////////////////////////////////////////////////////////////////////
#ifndef PI
#define PI 3.14159265358979324
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \def HALF_PI
/// \brief Equal to PI/2.0, useful for steering angles.
///
////////////////////////////////////////////////////////////////////////////////////
#ifndef HALF_PI
#define HALF_PI 1.57079632679489662
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Returns the minimum of two values.
///
/// \param a First element in comparison.
/// \param b Second element in comparison.
///
////////////////////////////////////////////////////////////////////////////////////
#ifndef MIN
template <class T>
inline T MIN(T a, T b)
{
return ( ( (a) < (b) ) ? (a) : (b) );
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Returns the minimum of three values.
///
/// \param a First element in comparison.
/// \param b Second element in comparison.
/// \param c Third element in comparison.
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline T MIN(T a, T b, T c)
{
return MIN(MIN(a, b), c);
}
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \def MAX
/// \brief Returns the maximum of two values.
///
////////////////////////////////////////////////////////////////////////////////////
#ifndef MAX
#define MAX(a,b) ( ( (a) > (b) ) ? (a) : (b) )
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \def DEG2RAD
/// \brief Converts from degrees to radians.
/// \return Value converted to radians, (double).
///
////////////////////////////////////////////////////////////////////////////////////
#ifndef DEG2RAD
#define DEG2RAD(deg) ( (deg*0.0174532925) )
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \def RAD2DEG
/// \brief Converts from radians to degrees.
/// \return Value converted to degrees, (double).
///
////////////////////////////////////////////////////////////////////////////////////
#ifndef RAD2DEG
#define RAD2DEG(rad) ( (rad*57.2957795) )
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Checks if two strings are equal
/// \param s1 First string to compare
/// \param s2 Second string to compare
/// \return True if strings are identical, false otherwise
///
////////////////////////////////////////////////////////////////////////////////////
inline bool EQ(const char *s1, const char *s2)
{
if (!s1 || !s2)
return false;
return !strcmp(s1, s2);
}
#if !defined(RGB)
inline int RGB(unsigned char r, unsigned char g, unsigned char b)
{
return (int)r | (int)g << 8 | (int) b << 16;
}
#endif
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Extract the RGB triplet from interleved data.
///
/// \param rgb Interleved rgb data
/// \param r Red value extracted.
/// \param g Green value extracted.
/// \param b Blue value extracted
///
////////////////////////////////////////////////////////////////////////////////////
inline void GETRGB(int rgb, unsigned char &r, unsigned char &g, unsigned char &b)
{
r = (unsigned char)rgb;
g = (unsigned char)(rgb >> 8);
b = (unsigned char)(rgb >> 16);
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Converts a string to uppercase and returns it
///
/// \param in String to convert (modifies string pointed to)
/// \return The same string that was just modified
///
////////////////////////////////////////////////////////////////////////////////////
inline char *strToUpper(char *in)
{
int size = (int)strlen(in);
for (int i = 0; i < size; i++)
{
in[i] = (char)toupper(in[i]);
}
return in;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Caps to a specified value
///
/// \param t Value to cap
/// \param cap The cap
/// \return Capped value
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline T CAP(T t, const T cap)
{
if (t > cap)
t = cap;
return t;
}
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Caps between two values
///
/// \param t Value to cap
/// \param low The cap on the low end
/// \param high The cap on the high end
/// \return Capped value
///
////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline T CAP(T t, const T low, const T high)
{
if (t < low)
t = low;
else if (t > high)
t = high;
return t;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \brief Returns the current date and time in a string format
///
/// \return Const pointer to a static string (not thread safe)
///
////////////////////////////////////////////////////////////////////////////////
inline const char* GET_DATETIME_STR()
{
static char str[256];
time_t rawtime;
tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
sprintf(str, "%s", asctime(timeinfo));
str[strlen(str)-1] = 0; // remove trailing \n
return str;
time_t now = time(0);
//cout << "Number of sec since January 1,1970:" << now << endl;
tm *ltm = localtime(&now);
// print various components of tm structure.
//cout << "Year: "<< 1900 + ltm->tm_year << endl;
//cout << "Month: "<< 1 + ltm->tm_mon<< endl;
//cout << "Day: "<< ltm->tm_mday << endl;
//cout << "Time: "<< 1 + ltm->tm_hour << ":";
//cout << 1 + ltm->tm_min << ":";
//cout << 1 + ltm->tm_sec << endl;
}
inline const char* GET_DATETIME_STR2()
{
static char str[256];
time_t now = time(0);
tm *ltm = localtime(&now);
// print various components of tm structure.
int year = 1900 + ltm->tm_year;
int month = 1 + ltm->tm_mon;
int day = ltm->tm_mday;
int hour = ltm->tm_hour;
int min = ltm->tm_min;
int sec = ltm->tm_sec;
sprintf(str,"%04d_%02d_%02d_%02d_%02d_%02d", year, month, day, hour, min, sec);
return str;
}
#endif
/* End of file */
|
858bbb52f05d086387e545bce1c920bf55702cec
|
c8a15a337e1519335532488653a93a08c0302b30
|
/include/proxc/process.hpp
|
70f081e7ade41d45f525d926f88c18847e2875bf
|
[
"BSL-1.0"
] |
permissive
|
edvardsp/libproxcplusplus
|
3433efb0a5c1ec8e5b02917823a19e856055656a
|
aea543d7de50a26fb424485a9eed458004f57510
|
refs/heads/master
| 2020-03-27T07:53:36.484187
| 2018-08-26T17:58:31
| 2018-08-26T17:58:31
| 146,202,037
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,951
|
hpp
|
process.hpp
|
// Copyright Oliver Kowalke 2009.
// Copyright Edvard Severin Pettersen 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include <iterator>
#include <tuple>
#include <type_traits>
#include <utility>
#include <proxc/config.hpp>
#include <proxc/runtime/context.hpp>
#include <proxc/runtime/scheduler.hpp>
#include <proxc/detail/apply.hpp>
#include <proxc/detail/delegate.hpp>
#include <proxc/detail/traits.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/range/irange.hpp>
PROXC_NAMESPACE_BEGIN
////////////////////////////////////////////////////////////////////////////////
// Process definition
////////////////////////////////////////////////////////////////////////////////
class Process
{
private:
using CtxPtr = boost::intrusive_ptr< runtime::Context >;
CtxPtr ctx_{};
public:
using Id = runtime::Context::Id;
Process() = default;
template< typename Fn
, typename ... Args
, typename
>
Process( Fn && fn, Args && ... args );
~Process() noexcept;
// make non-copyable
Process( Process const & ) = delete;
Process & operator = ( Process const & ) = delete;
// make moveable
Process( Process && ) noexcept;
Process & operator = ( Process && ) noexcept;
void swap( Process & other ) noexcept;
Id get_id() const noexcept;
void launch() noexcept;
void join();
void detach();
};
////////////////////////////////////////////////////////////////////////////////
// Process implementation
////////////////////////////////////////////////////////////////////////////////
template< typename Fn
, typename ... Args
, typename = std::enable_if_t<
detail::traits::are_callable_with_arg< Fn( Args ... ) >::value
>
>
Process::Process( Fn && fn, Args && ... args )
: ctx_{ runtime::Scheduler::make_work(
std::forward< Fn >( fn ),
std::forward< Args >( args ) ...
) }
{
}
////////////////////////////////////////////////////////////////////////////////
// Process methods
////////////////////////////////////////////////////////////////////////////////
template<typename Fn, typename ... Args>
Process proc( Fn &&, Args && ... );
namespace detail {
template< typename InputIt,
typename ... Fns
>
auto proc_for_impl( InputIt first, InputIt last, Fns && ... fns )
-> std::enable_if_t<
detail::traits::is_inputiterator< InputIt >{}
>
{
static_assert( detail::traits::are_callable_with_arg< typename InputIt::value_type, Fns ... >{},
"Supplied functions does not have the correct function signature" );
using FnT = detail::delegate< void( typename InputIt::value_type ) >;
using ArrT = std::array< FnT, sizeof...(Fns) >;
ArrT fn_arr{ { std::forward< Fns >( fns ) ... } };
const std::size_t total_size = sizeof...(Fns) * std::distance( first, last );
std::vector< Process > procs;
procs.reserve( total_size );
for ( auto data = first; data != last; ++data ) {
for ( const auto& fn : fn_arr ) {
procs.emplace_back( fn, *data );
procs.back().launch();
}
runtime::Scheduler::self()->yield();
}
std::for_each( procs.begin(), procs.end(),
[]( auto& proc ){ proc.join(); } );
}
template< typename Input,
typename ... Fns
>
auto proc_for_impl( Input first, Input last, Fns && ... fns )
-> std::enable_if_t<
std::is_integral< Input >{}
>
{
auto iota = boost::irange( first, last );
proc_for_impl( iota.begin(), iota.end(), std::forward< Fns >( fns ) ... );
}
} // namespace detail
template< typename Fn,
typename ... Args
>
Process proc( Fn && fn, Args && ... args )
{
static_assert( detail::traits::are_callable_with_arg< Fn( Args ... ) >::value,
"Supplied function is not callable with the given arguments");
return Process{
std::forward< Fn >( fn ),
std::forward< Args >( args ) ...
};
}
template< typename Input,
typename ... Fns
>
Process proc_for( Input first, Input last, Fns && ... fns )
{
return Process{
& detail::proc_for_impl< Input, Fns ... >,
first, last,
std::forward< Fns >( fns ) ...
};
}
template< typename InputIt
, typename = std::enable_if_t<
std::is_same<
Process,
typename std::decay<
typename std::iterator_traits< InputIt>::value_type
>::type
>::value
> >
Process proc_for( InputIt first, InputIt last )
{
return Process{
[first,last]{
std::for_each( first, last, std::mem_fn( & Process::launch ) );
std::for_each( first, last, std::mem_fn( & Process::join ) );
}
};
}
PROXC_NAMESPACE_END
|
6192de963b11ee3dfbfd098bfa29f5963f736f2d
|
737cc20f83064009c0406675d1d4ee9b2092a80b
|
/SampleFramework/renderer/src/gles2/GLES2RendererMaterial.h
|
ce68882e5c92e488ac1e0a20c1261aa0fb3f0a16
|
[
"MIT"
] |
permissive
|
jjuiddong/KarlSims
|
7e32e077da376deb1c0f270eb7855d84bfa6f7f1
|
e05108eb7d2e68bfe0a90a7550eba727424081b6
|
refs/heads/master
| 2020-04-29T03:49:14.572321
| 2016-10-13T03:30:46
| 2016-10-13T03:30:46
| 14,440,791
| 5
| 2
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,624
|
h
|
GLES2RendererMaterial.h
|
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
#ifndef GLES2_RENDERER_MATERIAL_H
#define GLES2_RENDERER_MATERIAL_H
#include <RendererConfig.h>
#if defined(RENDERER_ENABLE_GLES2)
#include <RendererMaterial.h>
#include "GLES2Renderer.h"
#if defined(RENDERER_ANDROID)
#include "android/AndroidSamplePlatform.h"
#elif defined(RENDERER_IOS)
#include "ios/IosSamplePlatform.h"
#endif
#include <set>
#include <set>
namespace SampleRenderer
{
class GLES2RendererMaterial : public RendererMaterial
{
public:
GLES2RendererMaterial(GLES2Renderer &renderer, const RendererMaterialDesc &desc);
virtual ~GLES2RendererMaterial(void);
virtual void setModelMatrix(const float *matrix)
{
PX_FORCE_PARAMETER_REFERENCE(matrix);
PX_ALWAYS_ASSERT();
}
virtual const Renderer& getRenderer() const { return m_renderer; }
/* Actually executes glUniform* and submits data saved in the m_program[m_currentPass].vsUniformsVec4/psUniformsVec4 */
void submitUniforms();
private:
virtual void bind(RendererMaterial::Pass pass, RendererMaterialInstance *materialInstance, bool instanced) const;
virtual void bindMeshState(bool instanced) const;
virtual void unbind(void) const;
virtual void bindVariable(Pass pass, const Variable &variable, const void *data) const;
VariableType GLTypetoVariableType(GLenum type);
GLint getAttribLocation(size_t usage, size_t index, Pass pass);
std::string mojoSampleNameToOriginal(Pass pass, const std::string& name);
private:
GLES2RendererMaterial &operator=(const GLES2RendererMaterial&) { return *this; }
private:
void loadCustomConstants(Pass pass);
friend class GLES2Renderer;
friend class GLES2RendererVertexBuffer;
friend class GLES2RendererDirectionalLight;
GLES2Renderer &m_renderer;
GLenum m_glAlphaTestFunc;
mutable struct shaderProgram {
GLuint vertexShader;
GLuint fragmentShader;
GLuint program;
GLint modelMatrixUniform;
GLint viewMatrixUniform;
GLint projMatrixUniform;
GLint modelViewMatrixUniform;
GLint boneMatricesUniform;
GLint modelViewProjMatrixUniform;
GLint positionAttr;
GLint colorAttr;
GLint normalAttr;
GLint tangentAttr;
GLint boneIndexAttr;
GLint boneWeightAttr;
GLint texcoordAttr[8];
mutable std::set<std::string> vsUniformsCollected;
mutable std::set<std::string> psUniformsCollected;
size_t vsUniformsTotal;
size_t psUniformsTotal;
char* vsUniformsVec4;
GLuint vsUniformsVec4Location;
size_t vsUniformsVec4Size;
size_t vsUniformsVec4SizeInBytes;
char* psUniformsVec4;
GLuint psUniformsVec4Location;
size_t psUniformsVec4Size;
size_t psUniformsVec4SizeInBytes;
mojoResult* vertexMojoResult;
mojoResult* fragmentMojoResult;
shaderProgram();
~shaderProgram();
} m_program[NUM_PASSES];
mutable Pass m_currentPass;
};
}
#endif // #if defined(RENDERER_ENABLE_GLES2)
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.