http://programmingexamples.net/w/api.php?action=feedcontributions&user=Daviddoria&feedformat=atom
ProgrammingExamples - User contributions [en]
2024-03-28T13:18:33Z
User contributions
MediaWiki 1.23.5
http://programmingexamples.net/wiki/CPP/OpenMP/ParallelFor
CPP/OpenMP/ParallelFor
2016-11-22T01:21:49Z
<p>Daviddoria: Created page with "==ParallelFor.cpp== <source lang="cpp"> #include <iostream> int main(int,char*[]) { #pragma omp parallel for for(int x=0; x < 100; x++) { std::cout << x <..."</p>
<hr />
<div>==ParallelFor.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
<br />
int main(int,char*[])<br />
{<br />
#pragma omp parallel for<br />
for(int x=0; x < 100; x++)<br />
{<br />
std::cout << x << std::endl;<br />
}<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(ParallelFor)<br />
<br />
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")<br />
<br />
find_package(OpenMP REQUIRED)<br />
<br />
IF(OPENMP_FOUND)<br />
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")<br />
else()<br />
message(WARNING "OpenMP not available!")<br />
endif()<br />
<br />
ADD_EXECUTABLE(ParallelFor ParallelFor.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/OpenMP
OpenMP
2016-11-22T01:21:07Z
<p>Daviddoria: Created page with "Simple OpenMP examples. * Perform a parallel for loop"</p>
<hr />
<div>Simple OpenMP examples.<br />
<br />
* [[CPP/OpenMP/ParallelFor|Perform a parallel for loop]]</div>
Daviddoria
http://programmingexamples.net/wiki/Main_Page
Main Page
2016-11-22T01:20:32Z
<p>Daviddoria: </p>
<hr />
<div>==Welcome to ProgrammingExamples.net!==<br />
This site is intended to provide short, compilable code snippets demonstrating frequently used concepts in several programming languages. Please feel free to modify the existing examples, and add new examples!<br />
<br />
Please read [[Help:Editing|Editing Wiki Pages]] and [[Help:DosAndDonts|Do's and Don'ts]] before getting started.<br />
<br />
== Coding Standards ==<br />
We don't want to get too carried away here, but below are some guidelines.<br />
<br />
* Use a sensible and internally consistent indentation scheme<br />
* Use "best coding practices" for your language<br />
* Use descriptive, fully spelled variable names (in English please)<br />
** Good: dispatchTable, dispatch_table<br />
** Bad: dispTbl, disp_tbl, mesaDespacho, avsändande_bord<br />
* Comment (only) to clarify your code or your intention.<br />
<br />
== Languages ==<br />
* [[CPP|C++]]<br />
* [[Java]]<br />
* [[Python]]<br />
* [[Perl]]<br />
* [[Bash]]<br />
* [[Matlab]]<br />
<br />
== Libraries ==<br />
* [[Boost]]<br />
* [[Eigen]]<br />
* [[OpenMP]]<br />
<br />
== GUI Systems ==<br />
* [[Qt]]<br />
* [[wxWidgets]]<br />
<br />
== Visualization/Graphics/Images ==<br />
* [http://www.vtk.org/Wiki/VTK/Examples/Cxx VTK]<br />
* [http://www.itk.org/Wiki/ITK/Examples ITK]<br />
* [[OpenGL]]<br />
<br />
== Computer Vision ==<br />
* [[OpenCV]]<br />
* [[PCL]]</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/decltype
CPP/decltype
2016-11-20T12:59:08Z
<p>Daviddoria: Created page with "==decltype.cpp== <source lang="cpp"> #include <iostream> void variable() { float a = 1.2f; decltype(a) b = a + .3; std::cout << b << std::endl; } float f() {..."</p>
<hr />
<div>==decltype.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
<br />
void variable()<br />
{<br />
float a = 1.2f;<br />
<br />
decltype(a) b = a + .3;<br />
<br />
std::cout << b << std::endl;<br />
}<br />
<br />
float f()<br />
{<br />
return 1.2f;<br />
}<br />
<br />
void func()<br />
{<br />
decltype(f()) b = f() + .3;<br />
<br />
std::cout << b << std::endl;<br />
}<br />
<br />
int main(int,char*[])<br />
{<br />
variable();<br />
func();<br />
<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(decltype)<br />
<br />
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")<br />
<br />
ADD_EXECUTABLE(decltype decltype.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP
CPP
2016-11-20T12:58:38Z
<p>Daviddoria: </p>
<hr />
<div>= C++ =<br />
A statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a "middle-level" language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named C with Classes. It was renamed C++ in 1983. (http://en.wikipedia.org/wiki/C++)<br />
----<br />
=== Formatting ===<br />
* [[CPP/Formatting/Decimals|Number of decimals (fixed and setprecision)]]<br />
<br />
=== General Examples ===<br />
* [[CPP/decltype|Get the type of a variable or function]]<br />
* [[CPP/bind|Bind different sets of arguments to a function]]<br />
* [[CPP/Pragma|Compile time output (pragma message)]]<br />
* [[CPP/CustomIterator|A custom iterator]]<br />
* [[CPP/StaticConstInitialization|Static const initialization]]<br />
* [[CPP/StaticInheritance|Static inheritance]]<br />
* [[CPP/StaticFunction|Static function]]<br />
* [[CPP/recursion|Recursion - a recursive function]]<br />
* [[CPP/unique_ptr|unique_ptr]]<br />
* [[CPP/Functor|Functor]]<br />
* [[CPP/ReturnByReference|Return a value by reference]]<br />
* [[CPP/IntToHex|Convert an int to hex]]<br />
* [[CPP/HexToInt|Convert a hex number to an int]]<br />
* [[CPP/AnonymousNamespace|Anonymous namespace]]<br />
* [[CPP/2DVector|2D Vector]]<br />
* [[CPP/AlphebetizeString|Alphabetize a vector of strings]]<br />
* [[CPP/ZeroPad|Pad a number with zeros]]<br />
* [[CPP/BinaryIO|Binary input and output]]<br />
* [[CPP/ExecuteLinuxCommand|Execute a linux command]]<br />
* [[CPP/Casting|Casting]]<br />
* [[CPP/KeyboardInput|Keyboard input]]<br />
* [[CPP/CommandLineArguments|Command line arguments]]<br />
* [[CPP/DeepCopy|Deep copy]]<br />
* [[CPP/DefaultArguments|Default arguments]]<br />
* [[CPP/Enum|Enum]]<br />
* [[CPP/Exceptions|Exceptions (try/catch)]]<br />
* [[CPP/Infinity|Infinity]]<br />
* [[CPP/Logging|Logging]]<br />
* [[CPP/Namespaces|Namespaces]]<br />
* [[CPP/NAN|NAN (not a number)]]<br />
* [[CPP/OverloadOperator|Overload operator]]<br />
* [[CPP/ParallelSort|Parallel sort]]<br />
* [[CPP/RandomNumbers|Random numbers]]<br />
* [[CPP/StringStream|StringStream]]<br />
* [[CPP/Struct|Struct]]<br />
* [[CPP/Switch|Switch]]<br />
* [[CPP/Typedef|Typedef]]<br />
* [[CPP/KeepSortedList|Keeping a Sorted List of Custom Records]]<br />
<br />
=== I/O ===<br />
* [[CPP/IO/Setw|Column width (setw)]]<br />
* [[CPP/IO/FileInput|File input]]<br />
* [[CPP/IO/FileOutput|File output]]<br />
* [[CPP/IO/ReadingLines|Reading lines from a text file]]<br />
<br />
=== Strings ===<br />
* [[CPP/Strings/Compare|Compare strings]]<br />
* [[CPP/Strings/Concatenate|Concatenate]]<br />
* [[CPP/Strings/CountCharacters|Count characters]]<br />
* [[CPP/Strings/Split|Split/parse]]<br />
* [[CPP/Strings/Case_Conversion|Case conversion]]<br />
* [[CPP/Strings/SingleCharacterTag|Find the contents of a single character tag]]<br />
* [[CPP/Strings/FindAndReplace|Replace a substring with a replacement string (find and replace)]]<br />
* [[CPP/Strings/Find|Find the position of a substring]]<br />
* [[CPP/Strings/DetectPunctuation|Detect punctuation (ispunct)]]<br />
<br />
=== Classes ===<br />
* [[CPP/Classes/ConstructorInheritance|Constructor inheritance]]<br />
* [[CPP/Classes/InitializationList|Initialization list]]<br />
* [[CPP/Classes/DerivedClass|Derived class]]<br />
* [[CPP/Classes/DownCasting|Down casting]]<br />
* [[CPP/Classes/FriendClass|Friend class]]<br />
* [[CPP/Classes/NestedClasses|Nested classes]]<br />
* [[CPP/Classes/PureVirtualFunction|Pure virtual function]]<br />
* [[CPP/Classes/Singleton|Singleton]]<br />
* [[CPP/Classes/Conversion Function|Conversion Function]]<br />
<br />
=== Templates ===<br />
* [[CPP/Templates/FunctionTemplateHeaderOnly|Function template (header only)]]<br />
* [[CPP/Templates/FunctionTemplateExplicitInstantiation|Function template (explicit instantiation)]]<br />
* [[CPP/FunctionTemplateSpecialization|Function template specialization]]<br />
* [[CPP/Templates/ClassTemplateHeaderOnly|Class template (header only)]]<br />
* [[CPP/Templates/ClassTemplateExplicitInstantiation|Class template (explicit instantiation)]]<br />
* [[CPP/Templates/MemberFunctionTemplate|A member function template]]<br />
* [[CPP/Templates/PartialClassSpecialization|Partially specialize a class template]]<br />
<br />
=== Loops ===<br />
* [[CPP/Loops/DoWhile|Do while]]<br />
* [[CPP/Loops/While|While]]<br />
* [[CPP/Loops/For|For]]<br />
<br />
=== STL Data Structures ===<br />
*[[CPP/STL/Complex|Complex]]<br />
*[[CPP/STL/Heap|Heap]]<br />
*[[CPP/STL/List|List]]<br />
*[[CPP/STL/Map|Map]]<br />
*[[CPP/STL/MultiMap|MultiMap]]<br />
*[[CPP/STL/MultiSet|MultiSet]]<br />
*[[CPP/STL/Pair|Pair]]<br />
*[[CPP/STL/PriorityQueue|Priority queue]]<br />
*[[CPP/STL/Queue|Queue]]<br />
*[[CPP/STL/Stack|Stack]]<br />
*[[CPP/STL/String|String]]<br />
*[[CPP/STL/Tuple|Tuple]]<br />
*[[CPP/STL/IteratorFromObject|Iterator from object]]<br />
<br />
==== Vector ====<br />
*[[CPP/STL/Vector|Vector]]<br />
*[[CPP/STL/Vector/RemoveElement|Remove an element from a vector]] delete, erase<br />
*[[CPP/STL/Vector/Reverse|Reverse the elements in a vector]]<br />
<br />
==== Set ====<br />
*[[CPP/STL/Set|Set]]<br />
*[[CPP/STL/Set/RemoveElement|Remove an element from a set]]<br />
*[[CPP/STL/Set/MergeSets|Merge sets]]<br />
*[[CPP/STL/Set/SearchForElement|Search for an element (find)]]<br />
*[[CPP/STL/Set/SetCustomClass|Custom class]]<br />
*[[CPP/STL/Set/SetCustomComparison|Custom comparison operator]]<br />
*[[CPP/STL/Set/BoundedInsert|A custom function to insert an element into the set only if it is less than an element currently in the set, and keep the same size]]<br />
<br />
=== STL Algorithms ===<br />
* [[CPP/STL/RandomShuffle|Random shuffle]]<br />
* [[CPP/STL/Sort|Sort a vector]]<br />
* [[CPP/STL/SetDifference|Find the different elements in two containers (set_difference)]]<br />
* [[CPP/STL/RandomData|Random data (std::generate)]]<br />
* [[CPP/STL/ForEach|ForEach]]<br />
* [[CPP/STL/VectorMinAndMax|VectorMinAndMax]]<br />
<br />
=== Debugging ===<br />
* [[CPP/Debugging/Assert|Assert]]<br />
* [[CPP/Debugging/LineNumbers|LineNumbers]]<br />
<br />
=== C++ TR1 ===<br />
*[[CPP/TR1/Regex_Tokenising|Tokenising with RegEx]]<br />
<br />
=== C++0x ===<br />
*[[CPP/C++0x/TheBigFive|The Big Five]]<br />
*[[CPP/C++0x/VectorInitialization|Vector initialization]]<br />
*[[CPP/C++0x/VectorMinMax|VectorMinMax]]<br />
*[[CPP/C++0x/Hash|Hash]]<br />
*[[CPP/C++0x/UnorderedSet|Unordered set]]<br />
*[[CPP/C++0x/Lambda|Lambda]]<br />
<br />
=== Math ===<br />
*[[CPP/Math/Exponential|Exponential function]]<br />
*[[CPP/Math/MinMax|Min and Max]]<br />
*[[CPP/Math/Trig|Trig functions]]<br />
*[[CPP/Math/SumVector|Sum elements in a vector (accumulate)]]<br />
*[[CPP/Math/Pi|Mathematic constant Pi = 3.14...]]<br />
*[[CPP/Math/Median|Median of a vector]]<br />
<br />
=== C-Style Programming Techniques ===<br />
* [[CPP/Array|Array]]<br />
* [[CPP/2DArray|2D Array]]<br />
* [[CPP/CharacterArray|Character array]]<br />
* [[CPP/Macros|Macros]]<br />
* [[CPP/FunctionPointer|Function pointer]]<br />
* [[CPP/VariableNumberOfArguments|Variable number of function arguments]]<br />
<br />
=== Utility ===<br />
* [[CPP/Template Print|Generic Print]]<br />
* [[CPP/DataType Converter | Generic DataType Converter]]<br />
* [[CPP/Sockets | Sockets]]<br />
* [[CPP/PThreads | PThreads]]<br />
* [[CPP/TCPSocket | TCPSocket]]<br />
* [[CPP/Typeof | Typeof]]</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/bind
CPP/bind
2016-11-19T13:49:55Z
<p>Daviddoria: Created page with "==bind.cpp== <source lang="cpp"> #include <iostream> #include <functional> void add(int a, int b) { std::cout << "a: " << a << " b: " << b << std::endl; } int main(int,c..."</p>
<hr />
<div>==bind.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <functional><br />
<br />
void add(int a, int b)<br />
{<br />
std::cout << "a: " << a << " b: " << b << std::endl;<br />
}<br />
<br />
int main(int,char*[])<br />
{<br />
// free function, full call<br />
{<br />
std::function<void(int, int)> f = std::bind(add, std::placeholders::_1, std::placeholders::_2);<br />
f(1,2);<br />
}<br />
<br />
// free function, partial-arg call<br />
{<br />
std::function<void(int)> f = std::bind(add, 1, std::placeholders::_1);<br />
f(2);<br />
}<br />
<br />
// free function, no-arg call<br />
{<br />
std::function<void()> f = std::bind(add, 1, 2);<br />
f();<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(bind)<br />
<br />
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")<br />
<br />
ADD_EXECUTABLE(bind bind.cpp)<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP
CPP
2016-11-19T13:49:15Z
<p>Daviddoria: /* C++ */</p>
<hr />
<div>= C++ =<br />
A statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a "middle-level" language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named C with Classes. It was renamed C++ in 1983. (http://en.wikipedia.org/wiki/C++)<br />
----<br />
=== Formatting ===<br />
* [[CPP/Formatting/Decimals|Number of decimals (fixed and setprecision)]]<br />
<br />
=== General Examples ===<br />
* [[CPP/bind|Bind different sets of arguments to a function]]<br />
* [[CPP/Pragma|Compile time output (pragma message)]]<br />
* [[CPP/CustomIterator|A custom iterator]]<br />
* [[CPP/StaticConstInitialization|Static const initialization]]<br />
* [[CPP/StaticInheritance|Static inheritance]]<br />
* [[CPP/StaticFunction|Static function]]<br />
* [[CPP/recursion|Recursion - a recursive function]]<br />
* [[CPP/unique_ptr|unique_ptr]]<br />
* [[CPP/Functor|Functor]]<br />
* [[CPP/ReturnByReference|Return a value by reference]]<br />
* [[CPP/IntToHex|Convert an int to hex]]<br />
* [[CPP/HexToInt|Convert a hex number to an int]]<br />
* [[CPP/AnonymousNamespace|Anonymous namespace]]<br />
* [[CPP/2DVector|2D Vector]]<br />
* [[CPP/AlphebetizeString|Alphabetize a vector of strings]]<br />
* [[CPP/ZeroPad|Pad a number with zeros]]<br />
* [[CPP/BinaryIO|Binary input and output]]<br />
* [[CPP/ExecuteLinuxCommand|Execute a linux command]]<br />
* [[CPP/Casting|Casting]]<br />
* [[CPP/KeyboardInput|Keyboard input]]<br />
* [[CPP/CommandLineArguments|Command line arguments]]<br />
* [[CPP/DeepCopy|Deep copy]]<br />
* [[CPP/DefaultArguments|Default arguments]]<br />
* [[CPP/Enum|Enum]]<br />
* [[CPP/Exceptions|Exceptions (try/catch)]]<br />
* [[CPP/Infinity|Infinity]]<br />
* [[CPP/Logging|Logging]]<br />
* [[CPP/Namespaces|Namespaces]]<br />
* [[CPP/NAN|NAN (not a number)]]<br />
* [[CPP/OverloadOperator|Overload operator]]<br />
* [[CPP/ParallelSort|Parallel sort]]<br />
* [[CPP/RandomNumbers|Random numbers]]<br />
* [[CPP/StringStream|StringStream]]<br />
* [[CPP/Struct|Struct]]<br />
* [[CPP/Switch|Switch]]<br />
* [[CPP/Typedef|Typedef]]<br />
* [[CPP/KeepSortedList|Keeping a Sorted List of Custom Records]]<br />
<br />
=== I/O ===<br />
* [[CPP/IO/Setw|Column width (setw)]]<br />
* [[CPP/IO/FileInput|File input]]<br />
* [[CPP/IO/FileOutput|File output]]<br />
* [[CPP/IO/ReadingLines|Reading lines from a text file]]<br />
<br />
=== Strings ===<br />
* [[CPP/Strings/Compare|Compare strings]]<br />
* [[CPP/Strings/Concatenate|Concatenate]]<br />
* [[CPP/Strings/CountCharacters|Count characters]]<br />
* [[CPP/Strings/Split|Split/parse]]<br />
* [[CPP/Strings/Case_Conversion|Case conversion]]<br />
* [[CPP/Strings/SingleCharacterTag|Find the contents of a single character tag]]<br />
* [[CPP/Strings/FindAndReplace|Replace a substring with a replacement string (find and replace)]]<br />
* [[CPP/Strings/Find|Find the position of a substring]]<br />
* [[CPP/Strings/DetectPunctuation|Detect punctuation (ispunct)]]<br />
<br />
=== Classes ===<br />
* [[CPP/Classes/ConstructorInheritance|Constructor inheritance]]<br />
* [[CPP/Classes/InitializationList|Initialization list]]<br />
* [[CPP/Classes/DerivedClass|Derived class]]<br />
* [[CPP/Classes/DownCasting|Down casting]]<br />
* [[CPP/Classes/FriendClass|Friend class]]<br />
* [[CPP/Classes/NestedClasses|Nested classes]]<br />
* [[CPP/Classes/PureVirtualFunction|Pure virtual function]]<br />
* [[CPP/Classes/Singleton|Singleton]]<br />
* [[CPP/Classes/Conversion Function|Conversion Function]]<br />
<br />
=== Templates ===<br />
* [[CPP/Templates/FunctionTemplateHeaderOnly|Function template (header only)]]<br />
* [[CPP/Templates/FunctionTemplateExplicitInstantiation|Function template (explicit instantiation)]]<br />
* [[CPP/FunctionTemplateSpecialization|Function template specialization]]<br />
* [[CPP/Templates/ClassTemplateHeaderOnly|Class template (header only)]]<br />
* [[CPP/Templates/ClassTemplateExplicitInstantiation|Class template (explicit instantiation)]]<br />
* [[CPP/Templates/MemberFunctionTemplate|A member function template]]<br />
* [[CPP/Templates/PartialClassSpecialization|Partially specialize a class template]]<br />
<br />
=== Loops ===<br />
* [[CPP/Loops/DoWhile|Do while]]<br />
* [[CPP/Loops/While|While]]<br />
* [[CPP/Loops/For|For]]<br />
<br />
=== STL Data Structures ===<br />
*[[CPP/STL/Complex|Complex]]<br />
*[[CPP/STL/Heap|Heap]]<br />
*[[CPP/STL/List|List]]<br />
*[[CPP/STL/Map|Map]]<br />
*[[CPP/STL/MultiMap|MultiMap]]<br />
*[[CPP/STL/MultiSet|MultiSet]]<br />
*[[CPP/STL/Pair|Pair]]<br />
*[[CPP/STL/PriorityQueue|Priority queue]]<br />
*[[CPP/STL/Queue|Queue]]<br />
*[[CPP/STL/Stack|Stack]]<br />
*[[CPP/STL/String|String]]<br />
*[[CPP/STL/Tuple|Tuple]]<br />
*[[CPP/STL/IteratorFromObject|Iterator from object]]<br />
<br />
==== Vector ====<br />
*[[CPP/STL/Vector|Vector]]<br />
*[[CPP/STL/Vector/RemoveElement|Remove an element from a vector]] delete, erase<br />
*[[CPP/STL/Vector/Reverse|Reverse the elements in a vector]]<br />
<br />
==== Set ====<br />
*[[CPP/STL/Set|Set]]<br />
*[[CPP/STL/Set/RemoveElement|Remove an element from a set]]<br />
*[[CPP/STL/Set/MergeSets|Merge sets]]<br />
*[[CPP/STL/Set/SearchForElement|Search for an element (find)]]<br />
*[[CPP/STL/Set/SetCustomClass|Custom class]]<br />
*[[CPP/STL/Set/SetCustomComparison|Custom comparison operator]]<br />
*[[CPP/STL/Set/BoundedInsert|A custom function to insert an element into the set only if it is less than an element currently in the set, and keep the same size]]<br />
<br />
=== STL Algorithms ===<br />
* [[CPP/STL/RandomShuffle|Random shuffle]]<br />
* [[CPP/STL/Sort|Sort a vector]]<br />
* [[CPP/STL/SetDifference|Find the different elements in two containers (set_difference)]]<br />
* [[CPP/STL/RandomData|Random data (std::generate)]]<br />
* [[CPP/STL/ForEach|ForEach]]<br />
* [[CPP/STL/VectorMinAndMax|VectorMinAndMax]]<br />
<br />
=== Debugging ===<br />
* [[CPP/Debugging/Assert|Assert]]<br />
* [[CPP/Debugging/LineNumbers|LineNumbers]]<br />
<br />
=== C++ TR1 ===<br />
*[[CPP/TR1/Regex_Tokenising|Tokenising with RegEx]]<br />
<br />
=== C++0x ===<br />
*[[CPP/C++0x/TheBigFive|The Big Five]]<br />
*[[CPP/C++0x/VectorInitialization|Vector initialization]]<br />
*[[CPP/C++0x/VectorMinMax|VectorMinMax]]<br />
*[[CPP/C++0x/Hash|Hash]]<br />
*[[CPP/C++0x/UnorderedSet|Unordered set]]<br />
*[[CPP/C++0x/Lambda|Lambda]]<br />
<br />
=== Math ===<br />
*[[CPP/Math/Exponential|Exponential function]]<br />
*[[CPP/Math/MinMax|Min and Max]]<br />
*[[CPP/Math/Trig|Trig functions]]<br />
*[[CPP/Math/SumVector|Sum elements in a vector (accumulate)]]<br />
*[[CPP/Math/Pi|Mathematic constant Pi = 3.14...]]<br />
*[[CPP/Math/Median|Median of a vector]]<br />
<br />
=== C-Style Programming Techniques ===<br />
* [[CPP/Array|Array]]<br />
* [[CPP/2DArray|2D Array]]<br />
* [[CPP/CharacterArray|Character array]]<br />
* [[CPP/Macros|Macros]]<br />
* [[CPP/FunctionPointer|Function pointer]]<br />
* [[CPP/VariableNumberOfArguments|Variable number of function arguments]]<br />
<br />
=== Utility ===<br />
* [[CPP/Template Print|Generic Print]]<br />
* [[CPP/DataType Converter | Generic DataType Converter]]<br />
* [[CPP/Sockets | Sockets]]<br />
* [[CPP/PThreads | PThreads]]<br />
* [[CPP/TCPSocket | TCPSocket]]<br />
* [[CPP/Typeof | Typeof]]</div>
Daviddoria
http://programmingexamples.net/wiki/Boost/BGL
Boost/BGL
2016-11-17T01:51:25Z
<p>Daviddoria: </p>
<hr />
<div>=== Basics ===<br />
* [[CPP/Boost/CreateGraph|Create a graph]] - This is the most fundamental process of using BGL - creating a graph. This example explains 3 methods of creating a graph, using adjacency_list directly, and also using the directed_graph and undirected_graph subclasses.<br />
* [[CPP/Boost/BGL/EdgeExists|Check if an edge exists]] - If it does, you also get the edge_descriptor<br />
* [[CPP/Boost/BGL/CopyAGraph|Copy a graph]]<br />
* [[CPP/Boost/BGL/Directed/Weighted|Access an edge]]<br />
* [[CPP/Boost/RemoveVertex|Remove a vertex from a graph]]<br />
* [[CPP/Boost/RemoveEdge|Remove an edge from a graph]]<br />
* [[CPP/Boost/BGL/EdgeProperties|Add properties to edges]]<br />
* [[CPP/Boost/BGL/VertexProperties|Add properties to vertices]]<br />
* [[CPP/Boost/BGL/BundledProperties|Bundled properties]]<br />
* [[CPP/Boost/BGL/AdjacentVertices|Get a list of neighboring (adjacent) vertices]]<br />
* [[CPP/Boost/BGL/DirectedGraph|Directed graphs only give access to out edges]]<br />
* [[CPP/Boost/BGL/BidirectionalGraph|Bidirectional graphs give access to both in and out edges]]<br />
* [[CPP/Boost/BGL/NumberOfNeighbors|Number of incoming, outgoing, and total edges]]<br />
* [[CPP/Boost/BGL/BreadthFirstSearch|Breadth first search (BFS with a custom visitor)]]<br />
* [[CPP/Boost/BGL/MakeBFSVisitor|Breadth first search with make_bfs_visitor]]<br />
* [[CPP/Boost/BGL/DepthFirstSearch|Depth first search (DFS)]]<br />
<br />
=== Filtered graphs ===<br />
* [[CPP/Boost/BGL/FilteredGraphVertices|Filter a graph's vertices]]<br />
* [[CPP/Boost/BGL/FilteredGraphEdges|Filter a graph's edges]]<br />
<br />
=== Directed graphs ===<br />
* [[CPP/Boost/BGL/Directed/IterateEdges|Iterate over all edges in a directed graph]]<br />
<br />
=== Undirected graphs ===<br />
* [[CPP/Boost/BGL/Undirected/IterateEdges|Iterate over all edges in an undirected graph]]<br />
<br />
=== I/O ===<br />
* [[Boost/BGL/IO/ReadGraph|Read a graph from a file]]<br />
* [[Boost/BGL/IO/WriteGraph|Write a graph to a file]]<br />
* [[Boost/BGL/RelabelInputVertices|Relabel input vertices read from a dot file so they match the labels used in the file]]<br />
<br />
=== Algorithms ===<br />
<br />
* [[CPP/Boost/BGL/DijkstraDirected|Find the shortest path (Dijkstra) from a specified vertex to all other vertices in a directed graph]]<br />
* [[CPP/Boost/BGL/DijkstraUndirected|Find the shortest path (Dijkstra) from a specified vertex to all other vertices in an undirected graph]]<br />
* [[CPP/Boost/BGL/DijkstraComputePath|Find the shortest path (Dijkstra) from one specified vertex to another specified vertex in a graph]]<br />
* [[CPP/Boost/BGL/BetweennessCentralityClustering|Cluster a graph using betweenness centrality]]<br />
* [[CPP/Boost/BGL/MaxFlow|Find the max flow of a graph]]<br />
* [[CPP/Boost/BGL/PrimMST|Find the minimum spanning tree of a graph (Prim's algorithm)]]<br />
<br />
=== Visualization ===<br />
<br />
* [[CPP/Boost/BGL/InvisibleEdges|Create a graph with invisible edges]]<br />
<br />
=== Grid graphs ===<br />
<br />
* [[CPP/Boost/BGL/GridGraphProperties|Create properties on a grid graph]]<br />
* [[CPP/Boost/BGL/d_ary_heap_indirect|Priority queue that sorts by a property (d_ary_heap_indirect)]]<br />
* [[CPP/Boost/BGL/GridGraphVertexIterator|Grid graph vertex iterator]]<br />
<br />
=== Utilities ===<br />
<br />
* [[CPP/Boost/BGL/IndirectPriorityQueue|Priority queue that sorts by a property (d_ary_heap_indirect)]]</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/BGL/PrimMST
CPP/Boost/BGL/PrimMST
2016-11-17T01:51:03Z
<p>Daviddoria: </p>
<hr />
<div>==PrimMST.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
<br />
#include <boost/graph/graph_traits.hpp><br />
#include <boost/graph/adjacency_list.hpp><br />
#include <boost/graph/prim_minimum_spanning_tree.hpp><br />
<br />
using EdgeWeightProperty = boost::property<boost::edge_weight_t, double>;<br />
<br />
using GraphType = boost::adjacency_list<boost::setS, // OutEdgeContainer<br />
boost::vecS, // VertexContainer<br />
boost::undirectedS, boost::no_property, EdgeWeightProperty> ;<br />
<br />
using PredecessorContainer = std::vector<boost::graph_traits < GraphType >::vertex_descriptor>;<br />
<br />
GraphType CreateGraphFromPredecessors(const PredecessorContainer& predecessors)<br />
{<br />
GraphType g(predecessors.size());<br />
<br />
for(unsigned int vertexID = 0; vertexID < predecessors.size(); ++vertexID) {<br />
if(predecessors[vertexID] != vertexID) {<br />
add_edge(predecessors[vertexID], vertexID, g);<br />
}<br />
}<br />
<br />
return g;<br />
}<br />
<br />
void PrintEdges(GraphType g)<br />
{<br />
typedef boost::graph_traits<GraphType>::edge_iterator edge_iter;<br />
std::pair<edge_iter, edge_iter> edgePair;<br />
for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first) {<br />
std::cout << *(edgePair.first) << std::endl;<br />
}<br />
<br />
std::cout << std::endl;<br />
}<br />
<br />
int main(int,char*[])<br />
{<br />
// Create a graph object<br />
GraphType g(3);<br />
<br />
// Create a "triangle"<br />
<br />
EdgeWeightProperty weight0 = 5;<br />
add_edge(0, 1, weight0, g);<br />
<br />
EdgeWeightProperty weight1 = 3;<br />
add_edge(1, 2, weight1, g);<br />
<br />
EdgeWeightProperty weight2 = 4;<br />
add_edge(0, 2, weight2, g);<br />
<br />
PrintEdges(g);<br />
<br />
// Create a container to store the predecessors for each vertex. Upon completion of the algorithm, the edges (p[u],u) for all u in V are in the minimum spanning tree.<br />
PredecessorContainer predecessors(num_vertices(g));<br />
<br />
// "named parameter" signature<br />
prim_minimum_spanning_tree(g, &predecessors[0], boost::root_vertex(1));<br />
<br />
for (std::size_t i = 0; i != predecessors.size(); ++i) {<br />
<br />
if (predecessors[i] != i) {<br />
std::cout << "parent[" << i << "] = " << predecessors[i] << std::endl;<br />
}<br />
else {<br />
std::cout << "parent[" << i << "] = no predecessors (i.e. root node)" << std::endl;<br />
}<br />
}<br />
<br />
GraphType mst = CreateGraphFromPredecessors(predecessors);<br />
<br />
PrintEdges(mst);<br />
<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(PrimMST)<br />
<br />
set(Boost_USE_MULTITHREADED ON)<br />
FIND_PACKAGE(Boost 1.38 COMPONENTS program_options required)<br />
<br />
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})<br />
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})<br />
<br />
ADD_EXECUTABLE(PrimMST PrimMST.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/BGL/PrimMST
CPP/Boost/BGL/PrimMST
2016-11-10T11:58:11Z
<p>Daviddoria: </p>
<hr />
<div>==DijkstraDirected.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
<br />
#include <boost/graph/graph_traits.hpp><br />
#include <boost/graph/adjacency_list.hpp><br />
#include <boost/graph/prim_minimum_spanning_tree.hpp><br />
<br />
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;<br />
<br />
typedef boost::adjacency_list<boost::setS, // OutEdgeContainer<br />
boost::vecS, // VertexContainer<br />
boost::undirectedS, boost::no_property, EdgeWeightProperty> Graph;<br />
<br />
using PredecessorContainer = std::vector<boost::graph_traits < Graph >::vertex_descriptor>;<br />
<br />
Graph CreateGraphFromPredecessors(const PredecessorContainer& predecessors)<br />
{<br />
Graph g(predecessors.size());<br />
<br />
for(unsigned int vertexID = 0; vertexID < predecessors.size(); ++vertexID) {<br />
if(predecessors[vertexID] != vertexID) {<br />
add_edge(predecessors[vertexID], vertexID, g);<br />
}<br />
}<br />
<br />
return g;<br />
}<br />
<br />
void PrintEdges(Graph g)<br />
{<br />
typedef boost::graph_traits<Graph>::edge_iterator edge_iter;<br />
std::pair<edge_iter, edge_iter> edgePair;<br />
for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first) {<br />
std::cout << *(edgePair.first) << std::endl;<br />
}<br />
<br />
std::cout << std::endl;<br />
}<br />
<br />
int main(int,char*[])<br />
{<br />
// Create a graph object<br />
Graph g(3);<br />
<br />
// Create a "triangle"<br />
<br />
EdgeWeightProperty weight0 = 5;<br />
add_edge(0, 1, weight0, g);<br />
<br />
EdgeWeightProperty weight1 = 3;<br />
add_edge(1, 2, weight1, g);<br />
<br />
EdgeWeightProperty weight2 = 4;<br />
add_edge(0, 2, weight2, g);<br />
<br />
PrintEdges(g);<br />
<br />
// Create a container to store the predecessors for each vertex. Upon completion of the algorithm, the edges (p[u],u) for all u in V are in the minimum spanning tree.<br />
PredecessorContainer predecessors(num_vertices(g));<br />
<br />
// "named parameter" signature<br />
prim_minimum_spanning_tree(g, &predecessors[0], boost::root_vertex(1));<br />
<br />
for (std::size_t i = 0; i != predecessors.size(); ++i) {<br />
<br />
if (predecessors[i] != i) {<br />
std::cout << "parent[" << i << "] = " << predecessors[i] << std::endl;<br />
}<br />
else {<br />
std::cout << "parent[" << i << "] = no predecessors (i.e. root node)" << std::endl;<br />
}<br />
}<br />
<br />
Graph mst = CreateGraphFromPredecessors(predecessors);<br />
<br />
PrintEdges(mst);<br />
<br />
return 0;<br />
}<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(PrimMST)<br />
<br />
set(Boost_USE_MULTITHREADED ON)<br />
FIND_PACKAGE(Boost 1.38 COMPONENTS program_options required)<br />
<br />
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})<br />
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})<br />
<br />
ADD_EXECUTABLE(PrimMST PrimMST.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/BGL/PrimMST
CPP/Boost/BGL/PrimMST
2016-11-10T11:45:19Z
<p>Daviddoria: Created page with "==DijkstraDirected.cpp== <source lang="cpp"> #include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/prim_..."</p>
<hr />
<div>==DijkstraDirected.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
<br />
#include <boost/graph/graph_traits.hpp><br />
#include <boost/graph/adjacency_list.hpp><br />
#include <boost/graph/prim_minimum_spanning_tree.hpp><br />
<br />
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;<br />
<br />
typedef boost::adjacency_list<boost::setS, // OutEdgeContainer<br />
boost::vecS, // VertexContainer<br />
boost::undirectedS, boost::no_property, EdgeWeightProperty> Graph;<br />
<br />
int main(int,char*[])<br />
{<br />
// Create a graph object<br />
Graph g(3);<br />
<br />
EdgeWeightProperty e1 = 5;<br />
add_edge(0, 1, e1, g);<br />
<br />
EdgeWeightProperty e2 = 3;<br />
add_edge(1, 2, e2, g);<br />
<br />
std::vector < boost::graph_traits < Graph >::vertex_descriptor > parents(num_vertices(g));<br />
<br />
// "named parameter" signature<br />
prim_minimum_spanning_tree(g, &parents[0], boost::root_vertex(1));<br />
<br />
for (std::size_t i = 0; i != parents.size(); ++i) {<br />
<br />
if (parents[i] != i) {<br />
std::cout << "parent[" << i << "] = " << parents[i] << std::endl;<br />
}<br />
else {<br />
std::cout << "parent[" << i << "] = no parent" << std::endl;<br />
}<br />
}<br />
<br />
<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(PrimMST)<br />
<br />
set(Boost_USE_MULTITHREADED ON)<br />
FIND_PACKAGE(Boost 1.38 COMPONENTS program_options required)<br />
<br />
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})<br />
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})<br />
<br />
ADD_EXECUTABLE(PrimMST PrimMST.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Boost/BGL
Boost/BGL
2016-11-10T11:44:34Z
<p>Daviddoria: </p>
<hr />
<div>=== Basics ===<br />
* [[CPP/Boost/CreateGraph|Create a graph]] - This is the most fundamental process of using BGL - creating a graph. This example explains 3 methods of creating a graph, using adjacency_list directly, and also using the directed_graph and undirected_graph subclasses.<br />
* [[CPP/Boost/BGL/EdgeExists|Check if an edge exists]] - If it does, you also get the edge_descriptor<br />
* [[CPP/Boost/BGL/CopyAGraph|Copy a graph]]<br />
* [[CPP/Boost/BGL/Directed/Weighted|Access an edge]]<br />
* [[CPP/Boost/RemoveVertex|Remove a vertex from a graph]]<br />
* [[CPP/Boost/RemoveEdge|Remove an edge from a graph]]<br />
* [[CPP/Boost/BGL/EdgeProperties|Add properties to edges]]<br />
* [[CPP/Boost/BGL/VertexProperties|Add properties to vertices]]<br />
* [[CPP/Boost/BGL/BundledProperties|Bundled properties]]<br />
* [[CPP/Boost/BGL/AdjacentVertices|Get a list of neighboring (adjacent) vertices]]<br />
* [[CPP/Boost/BGL/DirectedGraph|Directed graphs only give access to out edges]]<br />
* [[CPP/Boost/BGL/BidirectionalGraph|Bidirectional graphs give access to both in and out edges]]<br />
* [[CPP/Boost/BGL/NumberOfNeighbors|Number of incoming, outgoing, and total edges]]<br />
* [[CPP/Boost/BGL/BreadthFirstSearch|Breadth first search (BFS with a custom visitor)]]<br />
* [[CPP/Boost/BGL/MakeBFSVisitor|Breadth first search with make_bfs_visitor]]<br />
* [[CPP/Boost/BGL/DepthFirstSearch|Depth first search (DFS)]]<br />
<br />
=== Filtered graphs ===<br />
* [[CPP/Boost/BGL/FilteredGraphVertices|Filter a graph's vertices]]<br />
* [[CPP/Boost/BGL/FilteredGraphEdges|Filter a graph's edges]]<br />
<br />
=== Directed graphs ===<br />
* [[CPP/Boost/BGL/Directed/IterateEdges|Iterate over all edges in a directed graph]]<br />
<br />
=== Undirected graphs ===<br />
* [[CPP/Boost/BGL/Undirected/IterateEdges|Iterate over all edges in an undirected graph]]<br />
<br />
=== I/O ===<br />
* [[Boost/BGL/IO/ReadGraph|Read a graph from a file]]<br />
* [[Boost/BGL/IO/WriteGraph|Write a graph to a file]]<br />
* [[Boost/BGL/RelabelInputVertices|Relabel input vertices read from a dot file so they match the labels used in the file]]<br />
<br />
=== Algorithms ===<br />
<br />
* [[CPP/Boost/BGL/DijkstraDirected|Find the shortest path (Dijkstra) from a specified vertex to all other vertices in a directed graph]]<br />
* [[CPP/Boost/BGL/DijkstraUndirected|Find the shortest path (Dijkstra) from a specified vertex to all other vertices in an undirected graph]]<br />
* [[CPP/Boost/BGL/DijkstraComputePath|Find the shortest path (Dijkstra) from one specified vertex to another specified vertex in a graph]]<br />
* [[CPP/Boost/BGL/BetweennessCentralityClustering|Cluster a graph using betweenness centrality]]<br />
* [[CPP/Boost/BGL/MaxFlow|Find the max flow of a graph]]<br />
* [[CPP/Boost/BGL/PrimMST|Find the minimum spanning tree of a graph]]<br />
<br />
=== Visualization ===<br />
<br />
* [[CPP/Boost/BGL/InvisibleEdges|Create a graph with invisible edges]]<br />
<br />
=== Grid graphs ===<br />
<br />
* [[CPP/Boost/BGL/GridGraphProperties|Create properties on a grid graph]]<br />
* [[CPP/Boost/BGL/d_ary_heap_indirect|Priority queue that sorts by a property (d_ary_heap_indirect)]]<br />
* [[CPP/Boost/BGL/GridGraphVertexIterator|Grid graph vertex iterator]]<br />
<br />
=== Utilities ===<br />
<br />
* [[CPP/Boost/BGL/IndirectPriorityQueue|Priority queue that sorts by a property (d_ary_heap_indirect)]]</div>
Daviddoria
http://programmingexamples.net/wiki/OpenCV/ImageProcessing/ExtractChannel
OpenCV/ImageProcessing/ExtractChannel
2015-05-15T13:02:35Z
<p>Daviddoria: Created page with "You will want to make sure that you include the imgproc, highgui, and core, libraries in your project settings. ==ExtractChannel.cpp== <source lang="cpp"> #include "highgui.h..."</p>
<hr />
<div>You will want to make sure that you include the imgproc, highgui, and core, libraries in your project settings.<br />
<br />
==ExtractChannel.cpp==<br />
<source lang="cpp"><br />
#include "highgui.h" // required for imread()<br />
#include "cv.h"<br />
<br />
#include <iostream><br />
#include <vector><br />
<br />
int main(int, char*argv[])<br />
{<br />
cv::Mat image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);<br />
<br />
if(image.empty())<br />
{<br />
std::cout << "Can't read the image" << std::endl;<br />
return -1;<br />
}<br />
std::vector<cv::Mat> channels;<br />
cv::split(image, channels);<br />
cv::Mat r_channel = channels[0];<br />
<br />
for(int i=0; i < r_channel.rows; i++)<br />
{<br />
for(int j=0; j < r_channel.cols; j++)<br />
{<br />
std::cout << r_channel.at<uchar>(i,j) << std::endl;<br />
}<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
<br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(ExtractChannel)<br />
<br />
FIND_PACKAGE(OpenCV REQUIRED )<br />
INCLUDE_DIRECTORIES( ${OPENCV_INCLUDE_DIR} )<br />
<br />
ADD_EXECUTABLE(ExtractChannel ExtractChannel.cpp)<br />
TARGET_LINK_LIBRARIES(ExtractChannel ${OpenCV_LIBS})<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/OpenCV
OpenCV
2015-05-15T13:00:55Z
<p>Daviddoria: /* Image Processing */</p>
<hr />
<div>== Basics ==<br />
* [[OpenCV/Basics/Scalar|Scalar]]<br />
* [[OpenCV/Basics/Point|Point]]<br />
* [[OpenCV/Basics/Matrix|Matrix]]<br />
* [[OpenCV/Basics/MatrixType|Matrix type]]<br />
* [[OpenCV/Basics/MatrixInverse|MatrixInverse]]<br />
* [[OpenCV/Basics/Matrix3Channel|Matrix3Channel]]<br />
* [[OpenCV/Basics/MatrixProperties|MatrixProperties]]<br />
* [[OpenCV/Basics/PseudoInverse|PseudoInverse]]<br />
* [[OpenCV/Basics/MatrixMultiplication|MatrixMultiplication]]<br />
* [[OpenCV/Basics/Image|IplImage image type]]<br />
<br />
== Input/Output (IO) ==<br />
* [[OpenCV/IO/ReadImage|Read an image]]<br />
* [[OpenCV/IO/WriteImage|Write an image]]<br />
* [[OpenCV/IO/DisplayImage|Display an image]]<br />
<br />
== Calibration ==<br />
* [[OpenCV/CheckerboardCalibration|Calibrate the intrinsic parameters of a camera from a single image of a checkerboard]]<br />
<br />
== Convenience Functions ==<br />
* [[OpenCV/Convenience/ComposeP|Compose a projection matrix (P) from K, R, and T]]<br />
* [[OpenCV/Convenience/ConvertMatrixType|Convert the elements of a matrix from one type to another]]<br />
<br />
== Common Tasks ==<br />
* [[OpenCV/CommonTasks/RemoveDistortion|Remove distortion]]<br />
* [[OpenCV/CommonTasks/DecomposeProjectionMatrix|Decompose a projection matrix (P) into K,R,T]]<br />
<br />
== Image Processing ==<br />
* [[OpenCV/ImageProcessing/Smoothing|Smooth an image]]<br />
* [[OpenCV/ImageProcessing/ExtractChannel|Extract a channel of an image]]<br />
<br />
== Wish List ==<br />
* [[OpenCV/WishList/ConvertPointsHomogeneous|Convert between homogeneous and non-homogeneous coordinates]]<br />
* [[OpenCV/WishList/StereoRectifyUncalibrated|StereoRectifyUncalibrated function]]<br />
* [[OpenCV/WishList/DenseStereoCorrespondence|StereoBM, StereoSGBM]]<br />
* [[OpenCV/WishList/ProjectPoints|projectPoints function]]<br />
* [[OpenCV/WishList/Homography|findHomography function]]<br />
* [[OpenCV/WishList/StereoRectification|stereoRectify function]]<br />
* [[OpenCV/WishList/3DReconstruction|Reconstruct 3D points from correspondences in two images]]<br />
* [[OpenCV/WishList/IO/WriteMatrix|Write a matrix to a file]]<br />
* [[OpenCV/WishList/Stereo/stereoRectifyUncalibrated|Rectify images]]<br />
* [[OpenCV/WishList/3D/EstimateP|Estimate P from 2D/3D correspondences]]</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Eigen/SimplicialLDLT
CPP/Eigen/SimplicialLDLT
2015-05-15T10:20:17Z
<p>Daviddoria: Created page with "==SimplicialLDLT.cpp== <source lang="cpp"> #include <iostream> #include <Eigen/Sparse> int main(int, char *[]) { // Create matrix typedef Eigen::SparseMatrix<double> Spa..."</p>
<hr />
<div>==SimplicialLDLT.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
<br />
#include <Eigen/Sparse><br />
<br />
int main(int, char *[])<br />
{<br />
// Create matrix<br />
typedef Eigen::SparseMatrix<double> SparseMatrixType;<br />
SparseMatrixType A(2, 2);<br />
<br />
// Create the right-hand-side vector<br />
Eigen::VectorXd b(2);<br />
<br />
// Fill matrix<br />
A.coeffRef(0, 0) += 1;<br />
A.coeffRef(1, 1) += 3;<br />
<br />
// Fill vector<br />
b[0] = 1;<br />
b[1] = 2;<br />
<br />
// Solve the (symmetric) system<br />
Eigen::SimplicialLDLT<SparseMatrixType> sparseSolver(A);<br />
Eigen::VectorXd x = sparseSolver.solve(b);<br />
if(sparseSolver.info() != Eigen::Success)<br />
{<br />
throw std::runtime_error("Decomposition failed!");<br />
}<br />
<br />
std::cout << "Result: " << x << std::endl;<br />
<br />
return EXIT_SUCCESS;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(SimplicialLDLT)<br />
<br />
# Set the CMake variable to the value of the environment variable.<br />
# If the build is absolutely fresh, this will be the case if the CMake variable EIGEN3_INCLUDE_DIR is not set.<br />
if(NOT EIGEN3_INCLUDE_DIR)<br />
set(EIGEN3_INCLUDE_DIR $ENV{EIGEN3_INCLUDE_DIR})<br />
message("Set EIGEN3_INCLUDE_DIR to ${EIGEN3_INCLUDE_DIR} from environment variable of the same name.")<br />
else()<br />
message("EIGEN3_INCLUDE_DIR is ${EIGEN3_INCLUDE_DIR}")<br />
endif()<br />
<br />
if(NOT EIGEN3_FOUND)<br />
FIND_PACKAGE(Eigen3 REQUIRED) #requires FindEigen3.cmake to be in the source directory<br />
include_directories(${EIGEN3_INCLUDE_DIR})<br />
endif()<br />
<br />
ADD_EXECUTABLE(SimplicialLDLT SimplicialLDLT.cpp )<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Eigen
Eigen
2015-05-15T10:18:52Z
<p>Daviddoria: </p>
<hr />
<div>The following examples are frequent use cases of parts of the Eigen (http://eigen.tuxfamily.org/) library. Each example includes a CMakeLists.txt file so it can be easily compiled.<br />
<br />
* [[CPP/Eigen/Homogeneous|Convert a vector to and from homogeneous coordinates]]<br />
<br />
* [[CPP/Eigen/ProjectPoints|Project 3D points to 2D using a 3x4 projection (camera) matrix]]<br />
<br />
* [[CPP/Eigen/LevenbergMarquardt|LevenbergMarquardt Analytical Derivative]]<br />
<br />
* [[CPP/Eigen/LevenbergMarquardtNumerical|LevenbergMarquardt Numerical Derivative]]<br />
<br />
* [[CPP/Eigen/SparseMatrix|Sparse matrix]]<br />
<br />
* [[CPP/Eigen/SimplicialLDLT|Symmetric sparse matrix solver (SimplicialLDLT)]]<br />
<br />
* [[CPP/Eigen/STL vector of Eigen vectors|STLVector]]</div>
Daviddoria
http://programmingexamples.net/wiki/Eigen
Eigen
2015-05-15T10:18:36Z
<p>Daviddoria: </p>
<hr />
<div>The following examples are frequent use cases of parts of the Eigen (http://eigen.tuxfamily.org/) library. Each example includes a CMakeLists.txt file so it can be easily compiled.<br />
<br />
* [[CPP/Eigen/Homogeneous|Convert a vector to and from homogeneous coordinates]]<br />
<br />
* [[CPP/Eigen/ProjectPoints|Project 3D points to 2D using a 3x4 projection (camera) matrix]]<br />
<br />
* [[CPP/Eigen/LevenbergMarquardt|LevenbergMarquardt Analytical Derivative]]<br />
<br />
* [[CPP/Eigen/LevenbergMarquardtNumerical|LevenbergMarquardt Numerical Derivative]]<br />
<br />
* [[CPP/Eigen/SparseMatrix|Sparse matrix]]<br />
<br />
* [[CPP/Eigen/SparseMatrix|Symmetric sparse matrix solver (SimplicialLDLT)]]<br />
<br />
* [[CPP/Eigen/STL vector of Eigen vectors|STLVector]]</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/ClassFunctionPointer
CPP/Boost/ClassFunctionPointer
2015-05-12T19:37:37Z
<p>Daviddoria: /* CMakeLists.txt */</p>
<hr />
<div>==ClassFunctionPointer.cpp==<br />
<source lang="cpp"><br />
#include <boost/function.hpp><br />
#include <boost/bind.hpp><br />
<br />
#include <iostream><br />
<br />
class MyClass<br />
{<br />
private:<br />
double Update1()<br />
{<br />
std::cout << "Update1" << std::endl;<br />
}<br />
double Update2()<br />
{<br />
std::cout << "Update2" << std::endl;<br />
}<br />
<br />
public:<br />
boost::function< double() > Update;<br />
void SetUpdateMethod(int method)<br />
{<br />
if(method == 1)<br />
{<br />
this->Update = boost::bind(&MyClass::Update1,this);<br />
}<br />
if(method == 2)<br />
{<br />
this->Update = boost::bind(&MyClass::Update2,this);<br />
}<br />
}<br />
};<br />
<br />
int main () <br />
{<br />
MyClass a;<br />
a.SetUpdateMethod(1);<br />
a.Update();<br />
<br />
a.SetUpdateMethod(2);<br />
a.Update();<br />
<br />
return 0;<br />
}<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(ClassFunctionPointer)<br />
ADD_EXECUTABLE(ClassFunctionPointer ClassFunctionPointer.cpp)<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/ClassFunctionPointer
CPP/Boost/ClassFunctionPointer
2015-05-12T19:37:23Z
<p>Daviddoria: /* Function.cpp */</p>
<hr />
<div>==ClassFunctionPointer.cpp==<br />
<source lang="cpp"><br />
#include <boost/function.hpp><br />
#include <boost/bind.hpp><br />
<br />
#include <iostream><br />
<br />
class MyClass<br />
{<br />
private:<br />
double Update1()<br />
{<br />
std::cout << "Update1" << std::endl;<br />
}<br />
double Update2()<br />
{<br />
std::cout << "Update2" << std::endl;<br />
}<br />
<br />
public:<br />
boost::function< double() > Update;<br />
void SetUpdateMethod(int method)<br />
{<br />
if(method == 1)<br />
{<br />
this->Update = boost::bind(&MyClass::Update1,this);<br />
}<br />
if(method == 2)<br />
{<br />
this->Update = boost::bind(&MyClass::Update2,this);<br />
}<br />
}<br />
};<br />
<br />
int main () <br />
{<br />
MyClass a;<br />
a.SetUpdateMethod(1);<br />
a.Update();<br />
<br />
a.SetUpdateMethod(2);<br />
a.Update();<br />
<br />
return 0;<br />
}<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(Function)<br />
ADD_EXECUTABLE(Function Function.cpp)<br />
<br />
<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/Function
CPP/Boost/Function
2015-05-12T19:37:10Z
<p>Daviddoria: </p>
<hr />
<div>==Function.cpp==<br />
<source lang="cpp"><br />
#include <boost/function.hpp><br />
#include <boost/bind.hpp><br />
<br />
#include <iostream><br />
<br />
double Function0()<br />
{<br />
return 1;<br />
}<br />
<br />
double Function1(const int a)<br />
{<br />
return a+1;<br />
}<br />
<br />
int main () <br />
{<br />
boost::function<double ()> FunctionPointer0 = &Function0;<br />
boost::function<double (const int)> FunctionPointer1 = &Function1;<br />
<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(Function)<br />
ADD_EXECUTABLE(Function Function.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/ClassFunctionPointer
CPP/Boost/ClassFunctionPointer
2015-05-12T19:36:36Z
<p>Daviddoria: Created page with "==Function.cpp== <source lang="cpp"> #include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> class MyClass { private: double Update1() { std::cou..."</p>
<hr />
<div>==Function.cpp==<br />
<source lang="cpp"><br />
#include <boost/function.hpp><br />
#include <boost/bind.hpp><br />
<br />
#include <iostream><br />
<br />
class MyClass<br />
{<br />
private:<br />
double Update1()<br />
{<br />
std::cout << "Update1" << std::endl;<br />
}<br />
double Update2()<br />
{<br />
std::cout << "Update2" << std::endl;<br />
}<br />
<br />
public:<br />
boost::function< double() > Update;<br />
void SetUpdateMethod(int method)<br />
{<br />
if(method == 1)<br />
{<br />
this->Update = boost::bind(&MyClass::Update1,this);<br />
}<br />
if(method == 2)<br />
{<br />
this->Update = boost::bind(&MyClass::Update2,this);<br />
}<br />
}<br />
};<br />
<br />
int main () <br />
{<br />
MyClass a;<br />
a.SetUpdateMethod(1);<br />
a.Update();<br />
<br />
a.SetUpdateMethod(2);<br />
a.Update();<br />
<br />
return 0;<br />
}<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(Function)<br />
ADD_EXECUTABLE(Function Function.cpp)<br />
<br />
<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Boost
Boost
2015-05-12T19:36:21Z
<p>Daviddoria: /* Boost Examples */</p>
<hr />
<div>The following examples are frequent use cases of parts of the Boost (http://www.boost.org/) library. Each example includes a CMakeLists.txt file so it can be easily compiled.<br />
<br />
== Boost Examples ==<br />
* [[CPP/Boost/LexicalCast|lexical_cast - a replacement for std::stringstream]]<br />
* [[CPP/Boost/Bimap|Bidirectional (both ways) map]]<br />
* [[CPP/Boost/Function|Glorified function pointers (function.hpp and bind.hpp)]]<br />
* [[CPP/Boost/ClassFunctionPointer|Function pointers to class functions]]<br />
* [[CPP/Boost/Histogram|Create a histogram (accumulator)]]<br />
* [[CPP/Boost/Numeric/Matrix|Matrix]]<br />
* [[CPP/Boost/Numeric/MultiArray|Multi dimensional array]]<br />
* [[CPP/Boost/ProgramOptions/Simple|Simple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgramOptions/MultipleArguments|Multiple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgressBar|ProgressBar]]<br />
* [[CPP/Boost/Threads|Threads]]<br />
* [[CPP/Boost/ThreadsMember|Threads with member functions]]<br />
* [[CPP/Boost/ThreadCommunication|ThreadCommunication]]<br />
* [[CPP/Boost/Timer|Timer]]<br />
* [[CPP/Boost/Signals/Basic|Signal/slot pattern]]<br />
* [[CPP/Boost/Signals/Class|Signal/slot pattern with member functions]]<br />
* [[CPP/Boost/Signals/ClassMember|Signal/slot pattern with member classes]]<br />
* [[CPP/Boost/Signals/ClassMemberWithParameters|Signal/slot pattern with member classes which have parameters]]<br />
* [[CPP/Boost/Signals2/Basic|Signals2: Signal/slot pattern with type safety]]<br />
* [[CPP/Boost/Signals2/Parameters|Signals2: Signal/slot pattern with parameters type safety]]<br />
<br />
== Boost Graph Library (BGL) ==<br />
The Boost Graph Library is a c++ library for graph theoretic data structures and algorithms. There are several examples here: [[Boost/BGL|Boost Graph Library Examples]]<br />
<br />
=== Wish List ===<br />
Examples in this section are either shells or something is wrong with them that must be fixed before they can graduate into real examples.<br />
<br />
== Boost (Generic) Geometry Library ==<br />
* [[CPP/Boost/Geometry/DistanceBetweenPoints|Compute the distance between two points]]<br />
* [[CPP/Boost/Geometry/PointInPolygon|Determine if a point is inside of a polygon (within() function)]]<br />
* [[CPP/Boost/Geometry/Simplify|Simplify a polyline]]<br />
* [[CPP/Boost/Geometry/CoordinateConversion|Convert between spherical and Cartesian coordinates]]<br />
<br />
== Boost Iterators ==<br />
* [[CPP/Boost/Iterators/IndirectIterator|Access a collection of pointers as if it were a collection of objects]]<br />
<br />
== Boost Math Library ==<br />
=== uBLAS ===<br />
* [[CPP/Boost/Math/uBLAS/determinant]] Calculating the determinant of a matrix using boost::numeric::lu_factorize<br />
=== Tools ===<br />
* [[CPP/Boost/Math/Tools/brent_find_minima|brent_find_minima]] Find a bracketed minimum of a function<br />
* [[CPP/Boost/Math/Tools/TOMS748|TOMS748 root finding algorithm]] Find a bracketed root(zero) of a function<br />
<br />
== Heap ==<br />
* [[CPP/Boost/Heap/IndirectCompare|Indirect heap]] Sort a heap by values in a property map</div>
Daviddoria
http://programmingexamples.net/wiki/Boost
Boost
2015-05-12T19:36:00Z
<p>Daviddoria: /* Boost Examples */</p>
<hr />
<div>The following examples are frequent use cases of parts of the Boost (http://www.boost.org/) library. Each example includes a CMakeLists.txt file so it can be easily compiled.<br />
<br />
== Boost Examples ==<br />
* [[CPP/Boost/LexicalCast|lexical_cast - a replacement for std::stringstream]]<br />
* [[CPP/Boost/Bimap|Bidirectional (both ways) map]]<br />
* [[CPP/Boost/Function|Glorified function pointers (function.hpp and bind.hpp)]]<br />
* [[CPP/Boost/Function|Function pointers to class functions]]<br />
* [[CPP/Boost/Histogram|Create a histogram (accumulator)]]<br />
* [[CPP/Boost/Numeric/Matrix|Matrix]]<br />
* [[CPP/Boost/Numeric/MultiArray|Multi dimensional array]]<br />
* [[CPP/Boost/ProgramOptions/Simple|Simple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgramOptions/MultipleArguments|Multiple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgressBar|ProgressBar]]<br />
* [[CPP/Boost/Threads|Threads]]<br />
* [[CPP/Boost/ThreadsMember|Threads with member functions]]<br />
* [[CPP/Boost/ThreadCommunication|ThreadCommunication]]<br />
* [[CPP/Boost/Timer|Timer]]<br />
* [[CPP/Boost/Signals/Basic|Signal/slot pattern]]<br />
* [[CPP/Boost/Signals/Class|Signal/slot pattern with member functions]]<br />
* [[CPP/Boost/Signals/ClassMember|Signal/slot pattern with member classes]]<br />
* [[CPP/Boost/Signals/ClassMemberWithParameters|Signal/slot pattern with member classes which have parameters]]<br />
* [[CPP/Boost/Signals2/Basic|Signals2: Signal/slot pattern with type safety]]<br />
* [[CPP/Boost/Signals2/Parameters|Signals2: Signal/slot pattern with parameters type safety]]<br />
<br />
== Boost Graph Library (BGL) ==<br />
The Boost Graph Library is a c++ library for graph theoretic data structures and algorithms. There are several examples here: [[Boost/BGL|Boost Graph Library Examples]]<br />
<br />
=== Wish List ===<br />
Examples in this section are either shells or something is wrong with them that must be fixed before they can graduate into real examples.<br />
<br />
== Boost (Generic) Geometry Library ==<br />
* [[CPP/Boost/Geometry/DistanceBetweenPoints|Compute the distance between two points]]<br />
* [[CPP/Boost/Geometry/PointInPolygon|Determine if a point is inside of a polygon (within() function)]]<br />
* [[CPP/Boost/Geometry/Simplify|Simplify a polyline]]<br />
* [[CPP/Boost/Geometry/CoordinateConversion|Convert between spherical and Cartesian coordinates]]<br />
<br />
== Boost Iterators ==<br />
* [[CPP/Boost/Iterators/IndirectIterator|Access a collection of pointers as if it were a collection of objects]]<br />
<br />
== Boost Math Library ==<br />
=== uBLAS ===<br />
* [[CPP/Boost/Math/uBLAS/determinant]] Calculating the determinant of a matrix using boost::numeric::lu_factorize<br />
=== Tools ===<br />
* [[CPP/Boost/Math/Tools/brent_find_minima|brent_find_minima]] Find a bracketed minimum of a function<br />
* [[CPP/Boost/Math/Tools/TOMS748|TOMS748 root finding algorithm]] Find a bracketed root(zero) of a function<br />
<br />
== Heap ==<br />
* [[CPP/Boost/Heap/IndirectCompare|Indirect heap]] Sort a heap by values in a property map</div>
Daviddoria
http://programmingexamples.net/wiki/Matlab/ReadTextFile
Matlab/ReadTextFile
2013-03-21T15:38:47Z
<p>Daviddoria: Created page with '==ReadTextFile.m== <source lang="bash"> data=textread('LocalizationError.txt'); plot(data(:,1), data(:,2)) </source>'</p>
<hr />
<div>==ReadTextFile.m==<br />
<source lang="bash"><br />
data=textread('LocalizationError.txt');<br />
plot(data(:,1), data(:,2))<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Matlab
Matlab
2013-03-21T15:38:07Z
<p>Daviddoria: Created page with '* Read a space separated text file into a matrix'</p>
<hr />
<div>* [[Matlab/ReadTextFile|Read a space separated text file into a matrix]]</div>
Daviddoria
http://programmingexamples.net/wiki/Main_Page
Main Page
2013-03-21T15:37:31Z
<p>Daviddoria: /* Languages */</p>
<hr />
<div>==Welcome to ProgrammingExamples.net!==<br />
This site is intended to provide short, compilable code snippets demonstrating frequently used concepts in several programming languages. Please feel free to modify the existing examples, and add new examples!<br />
<br />
Please read [[Help:Editing|Editing Wiki Pages]] and [[Help:DosAndDonts|Do's and Don'ts]] before getting started.<br />
<br />
== Coding Standards ==<br />
We don't want to get too carried away here, but below are some guidelines.<br />
<br />
* Use a sensible and internally consistent indentation scheme<br />
* Use "best coding practices" for your language<br />
* Use descriptive, fully spelled variable names (in English please)<br />
** Good: dispatchTable, dispatch_table<br />
** Bad: dispTbl, disp_tbl, mesaDespacho, avsändande_bord<br />
* Comment (only) to clarify your code or your intention.<br />
<br />
== Languages ==<br />
* [[CPP|C++]]<br />
* [[Java]]<br />
* [[Python]]<br />
* [[Perl]]<br />
* [[Bash]]<br />
* [[Matlab]]<br />
<br />
== Libraries ==<br />
* [[Boost]]<br />
* [[Eigen]]<br />
<br />
== GUI Systems ==<br />
* [[Qt]]<br />
* [[wxWidgets]]<br />
<br />
== Visualization/Graphics/Images ==<br />
* [http://www.vtk.org/Wiki/VTK/Examples/Cxx VTK]<br />
* [http://www.itk.org/Wiki/ITK/Examples ITK]<br />
* [[OpenGL]]<br />
<br />
== Computer Vision ==<br />
* [[OpenCV]]<br />
* [[PCL]]</div>
Daviddoria
http://programmingexamples.net/wiki/Qt/Widgets/RadioButton
Qt/Widgets/RadioButton
2013-01-15T12:57:58Z
<p>Daviddoria: /* CMakeLists.txt */</p>
<hr />
<div>==main.cpp==<br />
<source lang="cpp"><br />
#include <QApplication><br />
<br />
#include "form.h"<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
Form form;<br />
<br />
form.show();<br />
return app.exec();<br />
}<br />
<br />
</source><br />
<br />
==form.cpp==<br />
<source lang="cpp"><br />
#include <QtGui><br />
<br />
#include "form.h"<br />
<br />
Form::Form(QWidget *parent)<br />
: QWidget(parent)<br />
{<br />
ui.setupUi(this);<br />
connect( this->ui.pushButton, SIGNAL( clicked() ), this, SLOT(pushButton_SetLabelText()) );<br />
connect( this->ui.radioButton, SIGNAL( clicked() ), this, SLOT(radioButton_SetLabelText()) );<br />
connect( this->ui.radioButton_2, SIGNAL( clicked() ), this, SLOT(radioButton_2_SetLabelText()) );<br />
}<br />
<br />
void Form::pushButton_SetLabelText()<br />
{<br />
<br />
if(this->ui.radioButton->isChecked())<br />
{<br />
this->ui.label->setText("1 selected");<br />
}<br />
<br />
if(this->ui.radioButton_2->isChecked())<br />
{<br />
this->ui.label->setText("2 selected");<br />
}<br />
<br />
}<br />
<br />
void Form::radioButton_SetLabelText()<br />
{<br />
<br />
if(this->ui.radioButton->isChecked())<br />
{<br />
this->ui.label->setText("1 clicked");<br />
}<br />
<br />
}<br />
<br />
void Form::radioButton_2_SetLabelText()<br />
{<br />
<br />
if(this->ui.radioButton_2->isChecked())<br />
{<br />
this->ui.label->setText("2 clicked");<br />
}<br />
<br />
}<br />
<br />
</source><br />
<br />
==form.h==<br />
<source lang="cpp"><br />
#ifndef FORM_H<br />
#define FORM_H<br />
<br />
#include "ui_form.h"<br />
<br />
class Form : public QWidget<br />
{<br />
Q_OBJECT<br />
<br />
public:<br />
Form(QWidget *parent = 0);<br />
<br />
public slots:<br />
void pushButton_SetLabelText();<br />
void radioButton_SetLabelText();<br />
void radioButton_2_SetLabelText();<br />
<br />
private:<br />
Ui::Form ui;<br />
};<br />
<br />
#endif<br />
<br />
</source><br />
<br />
==form.ui==<br />
<source lang="text"><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<ui version="4.0"><br />
<class>Form</class><br />
<widget class="QWidget" name="Form"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>400</width><br />
<height>300</height><br />
</rect><br />
</property><br />
<property name="windowTitle"><br />
<string>Form</string><br />
</property><br />
<widget class="QPushButton" name="pushButton"><br />
<property name="geometry"><br />
<rect><br />
<x>80</x><br />
<y>120</y><br />
<width>91</width><br />
<height>28</height><br />
</rect><br />
</property><br />
<property name="text"><br />
<string>PushButton</string><br />
</property><br />
</widget><br />
<widget class="QLabel" name="label"><br />
<property name="geometry"><br />
<rect><br />
<x>170</x><br />
<y>220</y><br />
<width>61</width><br />
<height>18</height><br />
</rect><br />
</property><br />
<property name="text"><br />
<string>TextLabel</string><br />
</property><br />
</widget><br />
<widget class="QRadioButton" name="radioButton"><br />
<property name="geometry"><br />
<rect><br />
<x>250</x><br />
<y>90</y><br />
<width>105</width><br />
<height>23</height><br />
</rect><br />
</property><br />
<property name="text"><br />
<string>RadioButton</string><br />
</property><br />
</widget><br />
<widget class="QRadioButton" name="radioButton_2"><br />
<property name="geometry"><br />
<rect><br />
<x>250</x><br />
<y>130</y><br />
<width>105</width><br />
<height>23</height><br />
</rect><br />
</property><br />
<property name="text"><br />
<string>RadioButton</string><br />
</property><br />
</widget><br />
</widget><br />
<resources/><br />
<connections/><br />
</ui><br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(RadioButton)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs form.ui)<br />
QT4_WRAP_CPP(MOCSrcs form.h)<br />
<br />
include_directories(${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(RadioButton main.cpp form.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(RadioButton ${QT_LIBRARIES})<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Boost/BGL
Boost/BGL
2012-10-03T19:41:09Z
<p>Daviddoria: /* Algorithms */</p>
<hr />
<div>=== Basics ===<br />
* [[CPP/Boost/CreateGraph|Create a graph]] - This is the most fundamental process of using BGL - creating a graph. This example explains 3 methods of creating a graph, using adjacency_list directly, and also using the directed_graph and undirected_graph subclasses.<br />
* [[CPP/Boost/BGL/EdgeExists|Check if an edge exists]] - If it does, you also get the edge_descriptor<br />
* [[CPP/Boost/BGL/CopyAGraph|Copy a graph]]<br />
* [[CPP/Boost/BGL/Directed/Weighted|Access an edge]]<br />
* [[CPP/Boost/RemoveVertex|Remove a vertex from a graph]]<br />
* [[CPP/Boost/RemoveEdge|Remove an edge from a graph]]<br />
* [[CPP/Boost/BGL/EdgeProperties|Add properties to edges]]<br />
* [[CPP/Boost/BGL/VertexProperties|Add properties to vertices]]<br />
* [[CPP/Boost/BGL/BundledProperties|Bundled properties]]<br />
* [[CPP/Boost/BGL/AdjacentVertices|Get a list of neighboring (adjacent) vertices]]<br />
* [[CPP/Boost/BGL/DirectedGraph|Directed graphs only give access to out edges]]<br />
* [[CPP/Boost/BGL/BidirectionalGraph|Bidirectional graphs give access to both in and out edges]]<br />
* [[CPP/Boost/BGL/NumberOfNeighbors|Number of incoming, outgoing, and total edges]]<br />
* [[CPP/Boost/BGL/BreadthFirstSearch|Breadth first search (BFS with a custom visitor)]]<br />
* [[CPP/Boost/BGL/MakeBFSVisitor|Breadth first search with make_bfs_visitor]]<br />
* [[CPP/Boost/BGL/DepthFirstSearch|Depth first search (DFS)]]<br />
<br />
=== Filtered graphs ===<br />
* [[CPP/Boost/BGL/FilteredGraphVertices|Filter a graph's vertices]]<br />
* [[CPP/Boost/BGL/FilteredGraphEdges|Filter a graph's edges]]<br />
<br />
=== Directed graphs ===<br />
* [[CPP/Boost/BGL/Directed/IterateEdges|Iterate over all edges in a directed graph]]<br />
<br />
=== Undirected graphs ===<br />
* [[CPP/Boost/BGL/Undirected/IterateEdges|Iterate over all edges in an undirected graph]]<br />
<br />
=== I/O ===<br />
* [[Boost/BGL/IO/ReadGraph|Read a graph from a file]]<br />
* [[Boost/BGL/IO/WriteGraph|Write a graph to a file]]<br />
* [[Boost/BGL/RelabelInputVertices|Relabel input vertices read from a dot file so they match the labels used in the file]]<br />
<br />
=== Algorithms ===<br />
<br />
* [[CPP/Boost/BGL/DijkstraDirected|Find the shortest path (Dijkstra) from a specified vertex to all other vertices in a directed graph]]<br />
* [[CPP/Boost/BGL/DijkstraUndirected|Find the shortest path (Dijkstra) from a specified vertex to all other vertices in an undirected graph]]<br />
* [[CPP/Boost/BGL/DijkstraComputePath|Find the shortest path (Dijkstra) from one specified vertex to another specified vertex in a graph]]<br />
* [[CPP/Boost/BGL/BetweennessCentralityClustering|Cluster a graph using betweenness centrality]]<br />
* [[CPP/Boost/BGL/MaxFlow|Find the max flow of a graph]]<br />
<br />
=== Visualization ===<br />
<br />
* [[CPP/Boost/BGL/InvisibleEdges|Create a graph with invisible edges]]<br />
<br />
=== Grid graphs ===<br />
<br />
* [[CPP/Boost/BGL/GridGraphProperties|Create properties on a grid graph]]<br />
* [[CPP/Boost/BGL/d_ary_heap_indirect|Priority queue that sorts by a property (d_ary_heap_indirect)]]<br />
* [[CPP/Boost/BGL/GridGraphVertexIterator|Grid graph vertex iterator]]<br />
<br />
=== Utilities ===<br />
<br />
* [[CPP/Boost/BGL/IndirectPriorityQueue|Priority queue that sorts by a property (d_ary_heap_indirect)]]</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/CommandLineArguments
CPP/CommandLineArguments
2012-09-27T13:28:11Z
<p>Daviddoria: </p>
<hr />
<div>==CommandLineArgumentsPractical.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <sstream><br />
<br />
// Pass this demo program a float and a string, like this:<br />
// ./MyProgram 2.3 david<br />
int main(int argc, char* argv[])<br />
{<br />
// Verify arguments<br />
const unsigned int expectedNumberOfArguments = 2;<br />
if(argc != expectedNumberOfArguments + 1) // argc is always at least 1 (the program name)<br />
{<br />
for(int argumentId = 0; argumentId < argc; ++argumentId)<br />
{<br />
std::cerr << "You have not passed the correct number of arguments! (You passed " << argc - 1<br />
<< " but " << expectedNumberOfArguments << " were expected.)" << std::endl;<br />
return EXIT_FAILURE;<br />
}<br />
}<br />
<br />
// Parse arguments<br />
<br />
// Add all of the arguments to a stringstream<br />
std::stringstream stringStream;<br />
for(int argumentId = 1; argumentId < argc; ++argumentId) // start at 1 because this is the first real argument<br />
{<br />
std::cout << "argument " << argumentId << ": " << argv[argumentId] << std::endl;<br />
stringStream << argv[argumentId] << " ";<br />
}<br />
<br />
// Declare the types of the arguments<br />
float myFloat;<br />
std::string myString;<br />
<br />
// Convert the arguments as their expected types<br />
stringStream >> myFloat >> myString;<br />
<br />
// Output arguments<br />
std::cout << "myFloat: " << myFloat << std::endl<br />
<< "myString: " << myString << std::endl;<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CommandLineArgumentsTutorial.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <string><br />
#include <sstream><br />
<br />
using namespace std;<br />
<br />
//test with<br />
//24.5 90.3<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
int NumArgs = argc - 1;<br />
cout << "Number of arguments: " << NumArgs << endl;<br />
<br />
//argv[0] is the EXE name & is always present.<br />
string FirstArgument = argv[1];<br />
string SecondArgument = argv[2];<br />
<br />
cout << "FirstArgument: " << FirstArgument << endl;<br />
cout << "SecondArgument: " << SecondArgument << endl;<br />
<br />
stringstream ssArg1, ssArg2;<br />
ssArg1 << FirstArgument;<br />
ssArg2 << SecondArgument;<br />
<br />
double dArg1, dArg2;<br />
ssArg1 >> dArg1;<br />
ssArg2 >> dArg2;<br />
<br />
cout << "FirstArgument: " << dArg1 << endl;<br />
cout << "SecondArgument: " << dArg2 << endl;<br />
<br />
std::string test = argv[1];<br />
cout << "argv[1]: " << argv[1] << endl;<br />
cout << "argv[1] string: " << test << endl;<br />
<br />
return 0;<br />
}<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/CommandLineArguments
CPP/CommandLineArguments
2012-09-27T13:23:14Z
<p>Daviddoria: </p>
<hr />
<div>==CommandLineArgumentsPractical.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <sstream><br />
<br />
int main(int argc, char* argv[])<br />
{<br />
// Verify arguments<br />
const unsigned int expectedNumberOfArguments = 2;<br />
if(argc != expectedNumberOfArguments + 1) // argc is always at least 1 (the program name)<br />
{<br />
for(int argumentId = 0; argumentId < argc; ++argumentId)<br />
{<br />
std::cerr << "You have not passed the correct number of arguments! (You passed " << argc - 1<br />
<< " but " << expectedNumberOfArguments << " were expected.)" << std::endl;<br />
return EXIT_FAILURE;<br />
}<br />
}<br />
<br />
// Parse arguments<br />
<br />
// Add all of the arguments to a stringstream<br />
std::stringstream stringStream;<br />
for(int argumentId = 1; argumentId < argc; ++argumentId) // start at 1 because this is the first real argument<br />
{<br />
std::cout << "argument " << argumentId << ": " << argv[argumentId] << std::endl;<br />
stringStream << argv[argumentId] << " ";<br />
}<br />
<br />
// Declare the types of the arguments<br />
int a;<br />
float b;<br />
<br />
// Convert the arguments as their expected types<br />
stringStream >> a >> b;<br />
<br />
// Output arguments<br />
std::cout << "a: " << a << std::endl<br />
<< "b: " << b << std::endl;<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==CommandLineArgumentsTutorial.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <string><br />
#include <sstream><br />
<br />
using namespace std;<br />
<br />
//test with<br />
//24.5 90.3<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
int NumArgs = argc - 1;<br />
cout << "Number of arguments: " << NumArgs << endl;<br />
<br />
//argv[0] is the EXE name & is always present.<br />
string FirstArgument = argv[1];<br />
string SecondArgument = argv[2];<br />
<br />
cout << "FirstArgument: " << FirstArgument << endl;<br />
cout << "SecondArgument: " << SecondArgument << endl;<br />
<br />
stringstream ssArg1, ssArg2;<br />
ssArg1 << FirstArgument;<br />
ssArg2 << SecondArgument;<br />
<br />
double dArg1, dArg2;<br />
ssArg1 >> dArg1;<br />
ssArg2 >> dArg2;<br />
<br />
cout << "FirstArgument: " << dArg1 << endl;<br />
cout << "SecondArgument: " << dArg2 << endl;<br />
<br />
std::string test = argv[1];<br />
cout << "argv[1]: " << argv[1] << endl;<br />
cout << "argv[1] string: " << test << endl;<br />
<br />
return 0;<br />
}<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/Geometry/CoordinateConversion
CPP/Boost/Geometry/CoordinateConversion
2012-09-25T17:45:50Z
<p>Daviddoria: Created page with '==Spherical.cpp== <source lang="cpp"> #include <boost/geometry/geometry.hpp> #include <iostream> static void CartesianToSpherical(); static void SphericalToCartesian(); int ma…'</p>
<hr />
<div>==Spherical.cpp==<br />
<source lang="cpp"><br />
#include <boost/geometry/geometry.hpp><br />
<br />
#include <iostream><br />
<br />
static void CartesianToSpherical();<br />
static void SphericalToCartesian();<br />
<br />
int main()<br />
{<br />
CartesianToSpherical();<br />
SphericalToCartesian();<br />
}<br />
<br />
void CartesianToSpherical()<br />
{<br />
std::cout << "CartesianToSpherical()" << std::endl;<br />
namespace bg = boost::geometry; // bg = 'B'oost 'G'eometry<br />
namespace cs = bg::cs; // cs = 'C'oordinate 'S'ystem<br />
<br />
typedef bg::model::point<long double, 3, cs::cartesian> CartesianType;<br />
CartesianType cartesian(0.084186, 0.0225576, 0.996195);<br />
<br />
typedef bg::model::point<long double, 2, cs::spherical<bg::degree> > SphericalType;<br />
SphericalType spherical;<br />
<br />
bg::strategy::transform::from_cartesian_3_to_spherical_polar_2<CartesianType, SphericalType> strategy;<br />
bg::transform(cartesian, spherical, strategy);<br />
<br />
std::cout<br />
<< "cartesian: " << bg::dsv(cartesian) << std::endl // dsv = Delimiter Separated Values<br />
<< "spherical: " << bg::dsv(spherical) << std::endl;<br />
}<br />
<br />
void SphericalToCartesian()<br />
{<br />
std::cout << "SphericalToCartesian()" << std::endl;<br />
namespace bg = boost::geometry; // bg = 'B'oost 'G'eometry<br />
namespace cs = bg::cs; // cs = 'C'oordinate 'S'ystem<br />
<br />
// (theta=5.0, phi=15.0)<br />
typedef bg::model::point<long double, 2, cs::spherical<bg::degree> > SphericalType;<br />
SphericalType spherical(15.0, 5.0);<br />
<br />
typedef bg::model::point<long double, 3, cs::cartesian> CartesianType;<br />
CartesianType cartesian;<br />
<br />
bg::strategy::transform::from_spherical_polar_2_to_cartesian_3<SphericalType, CartesianType> strategy;<br />
bg::transform(spherical, cartesian, strategy);<br />
<br />
std::cout<br />
<< "spherical: " << bg::dsv(spherical) << std::endl // dsv = Delimiter Separated Values<br />
<< "cartesian: " << bg::dsv(cartesian) << std::endl;<br />
}<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(Spherical)<br />
<br />
set(Boost_USE_MULTITHREADED ON)<br />
FIND_PACKAGE(Boost 1.38 COMPONENTS required)<br />
<br />
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})<br />
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})<br />
<br />
ADD_EXECUTABLE(Spherical Spherical.cpp)<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Boost
Boost
2012-09-25T17:45:23Z
<p>Daviddoria: /* Boost (Generic) Geometry Library */</p>
<hr />
<div>The following examples are frequent use cases of parts of the Boost (http://www.boost.org/) library. Each example includes a CMakeLists.txt file so it can be easily compiled.<br />
<br />
== Boost Examples ==<br />
* [[CPP/Boost/LexicalCast|lexical_cast - a replacement for std::stringstream]]<br />
* [[CPP/Boost/Bimap|Bidirectional (both ways) map]]<br />
* [[CPP/Boost/Function|Glorified function pointers (function.hpp and bind.hpp)]]<br />
* [[CPP/Boost/Histogram|Create a histogram (accumulator)]]<br />
* [[CPP/Boost/Numeric/Matrix|Matrix]]<br />
* [[CPP/Boost/Numeric/MultiArray|Multi dimensional array]]<br />
* [[CPP/Boost/ProgramOptions/Simple|Simple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgramOptions/MultipleArguments|Multiple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgressBar|ProgressBar]]<br />
* [[CPP/Boost/Threads|Threads]]<br />
* [[CPP/Boost/ThreadsMember|Threads with member functions]]<br />
* [[CPP/Boost/ThreadCommunication|ThreadCommunication]]<br />
* [[CPP/Boost/Timer|Timer]]<br />
* [[CPP/Boost/Signals/Basic|Signal/slot pattern]]<br />
* [[CPP/Boost/Signals/Class|Signal/slot pattern with member functions]]<br />
* [[CPP/Boost/Signals/ClassMember|Signal/slot pattern with member classes]]<br />
* [[CPP/Boost/Signals/ClassMemberWithParameters|Signal/slot pattern with member classes which have parameters]]<br />
* [[CPP/Boost/Signals2/Basic|Signals2: Signal/slot pattern with type safety]]<br />
* [[CPP/Boost/Signals2/Parameters|Signals2: Signal/slot pattern with parameters type safety]]<br />
<br />
== Boost Graph Library (BGL) ==<br />
The Boost Graph Library is a c++ library for graph theoretic data structures and algorithms. There are several examples here: [[Boost/BGL|Boost Graph Library Examples]]<br />
<br />
=== Wish List ===<br />
Examples in this section are either shells or something is wrong with them that must be fixed before they can graduate into real examples.<br />
<br />
== Boost (Generic) Geometry Library ==<br />
* [[CPP/Boost/Geometry/DistanceBetweenPoints|Compute the distance between two points]]<br />
* [[CPP/Boost/Geometry/PointInPolygon|Determine if a point is inside of a polygon (within() function)]]<br />
* [[CPP/Boost/Geometry/Simplify|Simplify a polyline]]<br />
* [[CPP/Boost/Geometry/CoordinateConversion|Convert between spherical and Cartesian coordinates]]<br />
<br />
== Boost Iterators ==<br />
* [[CPP/Boost/Iterators/IndirectIterator|Access a collection of pointers as if it were a collection of objects]]<br />
<br />
== Boost Math Library ==<br />
=== uBLAS ===<br />
* [[CPP/Boost/Math/uBLAS/determinant]] Calculating the determinant of a matrix using boost::numeric::lu_factorize<br />
=== Tools ===<br />
* [[CPP/Boost/Math/Tools/brent_find_minima|brent_find_minima]] Find a bracketed minimum of a function<br />
* [[CPP/Boost/Math/Tools/TOMS748|TOMS748 root finding algorithm]] Find a bracketed root(zero) of a function<br />
<br />
== Heap ==<br />
* [[CPP/Boost/Heap/IndirectCompare|Indirect heap]] Sort a heap by values in a property map</div>
Daviddoria
http://programmingexamples.net/wiki/Qt
Qt
2012-09-21T15:30:03Z
<p>Daviddoria: /* Building */</p>
<hr />
<div>== Building ==<br />
See this guide to get started: http://www.itk.org/Wiki/CMake/Tutorials/Qt<br />
<br />
== Simple Widgets ==<br />
* [[Qt/AutoConnect|Auto connect slots]]<br />
* [[Qt/ToolbarIcons|Toolbar icons]]<br />
* [[Qt/Icons|Use icons without resources (QCommonStyle) - Old method]]<br />
* [[Qt/Toolbar|Display a toolbar (also an example of resources)]]<br />
* [[Qt/Dialog|Display a dialog]]<br />
* [[Qt/ProgrammaticButton|Programmatically create a button]]<br />
* [[Qt/ButtonWidget|Button widget (single inheritance)]]<br />
* [[Qt/ButtonWidgetMultipleInheritance|Button widget (multiple inheritance)]]<br />
* [[Qt/CallANormalFunction|Call a normal function from an event]]<br />
* [[Qt/Widgets/CheckBox|Check box widget]]<br />
* [[Qt/Widgets/ComboBox|Combo box widget]]<br />
* [[Qt/Widgets/ProgressBar|Progress bar widget]]<br />
* [[Qt/Widgets/ProgressBarMarquee|Progress bar marquee widget]]<br />
* [[Qt/Widgets/ProgressThreaded|Display a progress bar while a long operation is being processed]]<br />
* [[Qt/Widgets/Slider|Slider widget]]<br />
* [[Qt/Widgets/FileDialog|File dialog]]<br />
* [[Qt/Widgets/FileDialogDefaultSuffix|File dialog - append a specified suffix if one is not provided]]<br />
* [[Qt/Widgets/RadioButton|Radio button widget]]<br />
* [[Qt/Widgets/Timer|Timer]]<br />
* [[Qt/Widgets/Thread|Thread]]<br />
* [[Qt/Widgets/MessageBoxFromThread|MessageBox from a thread]]<br />
* [[Qt/Widgets/ThreadClassMessageBox|MessageBox from a class object within a thread]]<br />
* [[Qt/Widgets/QWidgetSubclass|QWidget subclass in a cpp file]]<br />
* [[Qt/File|Operations on files (exist, etc)]]<br />
* [[Qt/FileInfo|Information about a file (basename, path, extension, etc)]]<br />
* [[Qt/Widgets/FileMenu|File menu]]<br />
* [[Qt/Widgets/WidgetInsideMainWindow|Display a widget inside a main window]]<br />
* [[Qt/Widgets/WidgetTemplated|Display a templated widget inside a main window]]<br />
* [[Qt/Widgets/Cursor|Change the cursor]]<br />
* [[Qt/Widgets/LineEdit|LineEdit widget - a text box]]<br />
* [[Qt/Widgets/Label|Label]]<br />
<br />
== Model/View ==<br />
* [[Qt/ModelView/QAbstractTableModel|QAbstractTableModel]]<br />
* [[Qt/ModelView/ComboBoxOfCheckBoxes|ComboBox of CheckBoxes (QStandardItemModel, QStandardItem)]]<br />
* [[Qt/ModelView/StringListModelCheckable|A StringListModel with checkboxes]]<br />
* [[Qt/ModelView/StandardItemModel|A StandardItemModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelCheckable|An AbstractListModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelFileDialog|An AbstractListModel where one of the cells can be changed using a QFileDialog]]<br />
* [[Qt/ModelView/ListViewComboBox|A persistent ComboBox on a list view]]<br />
* [[Qt/ModelView/ItemSelectionModel|Track selected items in a model]]<br />
<br />
* [[Qt/ModelView/AbstractTableModelCheckable|A table with checkboxes]]<br />
<br />
== Utilities ==<br />
* [[Qt/Widgets/Time|Get the system time]]<br />
* [[Qt/Utilities/StatusBar|Status bar]]<br />
* [[Qt/Utilities/DragAndDropFiles|Drag and drop files onto a widget]]<br />
* [[Qt/Utilities/HandleItem|Add resize handles to a rectangle]]<br />
* [[Qt/Utilities/EventFilter|Handle another widgets event]]<br />
* [[Qt/Utilities/Settings|Save application settings]]<br />
<br />
== Other ==<br />
* [[Qt/Boost|Using Qt with Boost]]<br />
<br />
== Images ==<br />
* [[Qt/Images/Pixmap|QPixmap]]<br />
<br />
* [[Qt/Images/MovingAPixmap|Move a pixmap in a QGraphicsView]]<br />
<br />
* [[Qt/Images/SemiTransparentPixels|Make pixels semi-transparent]]<br />
<br />
* [[Qt/Images/RubberBand|Use a QRubberBand to indicate a selected region in an image]]<br />
<br />
* [[Qt/Images/RubberBandSignal|Customize QGraphicsView to monitor the RubberBand behavior]]<br />
<br />
== Delegates ==<br />
* [[Qt/Delegates/ComboBoxDelegate|A combobox in a TableView]]<br />
<br />
== Databases ==<br />
* [[Qt/Databases/ListView|A ListView of a table column]]<br />
<br />
== QWT ==<br />
* [[Qt/QWT/Plot|Simple plot]]<br />
<br />
== Events ==<br />
* [[Qt/Events/Resize|Resize a graphics item when the form is resized]]</div>
Daviddoria
http://programmingexamples.net/wiki/Qt/Utilities/Settings
Qt/Utilities/Settings
2012-09-18T15:32:50Z
<p>Daviddoria: Created page with '==Settings.cpp== <source lang="cpp"> #include <QtCore> #include <iostream> void LocalUsage(); void GlobalUsage(); int main(int argc, char *argv[]) { QCoreApplication app(arg…'</p>
<hr />
<div>==Settings.cpp==<br />
<source lang="cpp"><br />
#include <QtCore><br />
<br />
#include <iostream><br />
<br />
void LocalUsage();<br />
void GlobalUsage();<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
QCoreApplication app(argc, argv);<br />
<br />
LocalUsage();<br />
GlobalUsage();<br />
<br />
return 0;<br />
}<br />
<br />
void LocalUsage()<br />
{<br />
QSettings settings("MyCompany", "MyProgram");<br />
QString hello = "Hello, world!";<br />
// store a value<br />
settings.setValue("Greeting", hello); // creates ~/.config/OpenSourcePress/ConfigTest.conf<br />
<br />
// reset variable<br />
hello = "";<br />
// read value and assign to variable<br />
hello = settings.value("Greeting").toString();<br />
std::cout << hello.toStdString() << std::endl; // prints "Hello, world!"<br />
<br />
}<br />
<br />
void GlobalUsage()<br />
{<br />
QCoreApplication::setOrganizationName("MyCompany");<br />
//QCoreApplication::setOrganizationDomain("mysoft.com");<br />
QCoreApplication::setApplicationName("MyProgram");<br />
<br />
QSettings settings;<br />
QString hello = "Hello, world!";<br />
// store a value<br />
settings.setValue("Greeting", hello); // creates ~/.config/OpenSourcePress/ConfigTest.conf<br />
<br />
// reset variable<br />
hello = "";<br />
// read value and assign to variable<br />
hello = settings.value("Greeting").toString();<br />
std::cout << hello.toStdString() << std::endl; // prints "Hello, world!"<br />
}<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(Settings)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
INCLUDE_DIRECTORIES(${QT_QTXML_INCLUDE_DIR}) # Prevents "QtXml: No such file or directory"<br />
<br />
ADD_EXECUTABLE(Settings Settings.cpp)<br />
message(${QT_LIBRARIES})<br />
TARGET_LINK_LIBRARIES(Settings ${QT_LIBRARIES})<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Qt
Qt
2012-09-18T15:31:58Z
<p>Daviddoria: /* Utilities */</p>
<hr />
<div>== Building ==<br />
* [[Building on Windows]]<br />
<br />
== Simple Widgets ==<br />
* [[Qt/AutoConnect|Auto connect slots]]<br />
* [[Qt/ToolbarIcons|Toolbar icons]]<br />
* [[Qt/Icons|Use icons without resources (QCommonStyle) - Old method]]<br />
* [[Qt/Toolbar|Display a toolbar (also an example of resources)]]<br />
* [[Qt/Dialog|Display a dialog]]<br />
* [[Qt/ProgrammaticButton|Programmatically create a button]]<br />
* [[Qt/ButtonWidget|Button widget (single inheritance)]]<br />
* [[Qt/ButtonWidgetMultipleInheritance|Button widget (multiple inheritance)]]<br />
* [[Qt/CallANormalFunction|Call a normal function from an event]]<br />
* [[Qt/Widgets/CheckBox|Check box widget]]<br />
* [[Qt/Widgets/ComboBox|Combo box widget]]<br />
* [[Qt/Widgets/ProgressBar|Progress bar widget]]<br />
* [[Qt/Widgets/ProgressBarMarquee|Progress bar marquee widget]]<br />
* [[Qt/Widgets/ProgressThreaded|Display a progress bar while a long operation is being processed]]<br />
* [[Qt/Widgets/Slider|Slider widget]]<br />
* [[Qt/Widgets/FileDialog|File dialog]]<br />
* [[Qt/Widgets/FileDialogDefaultSuffix|File dialog - append a specified suffix if one is not provided]]<br />
* [[Qt/Widgets/RadioButton|Radio button widget]]<br />
* [[Qt/Widgets/Timer|Timer]]<br />
* [[Qt/Widgets/Thread|Thread]]<br />
* [[Qt/Widgets/MessageBoxFromThread|MessageBox from a thread]]<br />
* [[Qt/Widgets/ThreadClassMessageBox|MessageBox from a class object within a thread]]<br />
* [[Qt/Widgets/QWidgetSubclass|QWidget subclass in a cpp file]]<br />
* [[Qt/File|Operations on files (exist, etc)]]<br />
* [[Qt/FileInfo|Information about a file (basename, path, extension, etc)]]<br />
* [[Qt/Widgets/FileMenu|File menu]]<br />
* [[Qt/Widgets/WidgetInsideMainWindow|Display a widget inside a main window]]<br />
* [[Qt/Widgets/WidgetTemplated|Display a templated widget inside a main window]]<br />
* [[Qt/Widgets/Cursor|Change the cursor]]<br />
* [[Qt/Widgets/LineEdit|LineEdit widget - a text box]]<br />
* [[Qt/Widgets/Label|Label]]<br />
<br />
== Model/View ==<br />
* [[Qt/ModelView/QAbstractTableModel|QAbstractTableModel]]<br />
* [[Qt/ModelView/ComboBoxOfCheckBoxes|ComboBox of CheckBoxes (QStandardItemModel, QStandardItem)]]<br />
* [[Qt/ModelView/StringListModelCheckable|A StringListModel with checkboxes]]<br />
* [[Qt/ModelView/StandardItemModel|A StandardItemModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelCheckable|An AbstractListModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelFileDialog|An AbstractListModel where one of the cells can be changed using a QFileDialog]]<br />
* [[Qt/ModelView/ListViewComboBox|A persistent ComboBox on a list view]]<br />
* [[Qt/ModelView/ItemSelectionModel|Track selected items in a model]]<br />
<br />
* [[Qt/ModelView/AbstractTableModelCheckable|A table with checkboxes]]<br />
<br />
== Utilities ==<br />
* [[Qt/Widgets/Time|Get the system time]]<br />
* [[Qt/Utilities/StatusBar|Status bar]]<br />
* [[Qt/Utilities/DragAndDropFiles|Drag and drop files onto a widget]]<br />
* [[Qt/Utilities/HandleItem|Add resize handles to a rectangle]]<br />
* [[Qt/Utilities/EventFilter|Handle another widgets event]]<br />
* [[Qt/Utilities/Settings|Save application settings]]<br />
<br />
== Other ==<br />
* [[Qt/Boost|Using Qt with Boost]]<br />
<br />
== Images ==<br />
* [[Qt/Images/Pixmap|QPixmap]]<br />
<br />
* [[Qt/Images/MovingAPixmap|Move a pixmap in a QGraphicsView]]<br />
<br />
* [[Qt/Images/SemiTransparentPixels|Make pixels semi-transparent]]<br />
<br />
* [[Qt/Images/RubberBand|Use a QRubberBand to indicate a selected region in an image]]<br />
<br />
* [[Qt/Images/RubberBandSignal|Customize QGraphicsView to monitor the RubberBand behavior]]<br />
<br />
== Delegates ==<br />
* [[Qt/Delegates/ComboBoxDelegate|A combobox in a TableView]]<br />
<br />
== Databases ==<br />
* [[Qt/Databases/ListView|A ListView of a table column]]<br />
<br />
== QWT ==<br />
* [[Qt/QWT/Plot|Simple plot]]<br />
<br />
== Events ==<br />
* [[Qt/Events/Resize|Resize a graphics item when the form is resized]]</div>
Daviddoria
http://programmingexamples.net/wiki/Building_on_Windows
Building on Windows
2012-09-16T17:56:43Z
<p>Daviddoria: </p>
<hr />
<div>A typical CMakeLists.txt file on this site looks like this:<br />
<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
PROJECT(FileMenu)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs main.ui)<br />
QT4_WRAP_CPP(MOCSrcs filemenu.h)<br />
<br />
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(FileMenu main.cpp filemenu.h filemenu.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(FileMenu ${QT_LIBRARIES})<br />
</source><br />
<br />
However, when you build and run in Windows, you will get a console window that appears along with your GUI program. To fix this, you must do two things. First, add ${QT_QTMAIN_LIBRARY} to your target_link_libraries command. Second, you must specify /SUBSYSTEM:WINDOWS for all build configurations (Release, Debug, etc) that you want to not pop up the console window. An example is below, where when built in release mode, no console will appear:<br />
<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(FileMenu)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs main.ui)<br />
QT4_WRAP_CPP(MOCSrcs filemenu.h)<br />
<br />
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(FileMenu main.cpp filemenu.h filemenu.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(FileMenu ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})<br />
<br />
set_target_properties(FileMenu PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")<br />
<br />
</source><br />
<br />
If you want to set this for all build modes, simply use:<br />
<source lang="cmake"><br />
set_target_properties(FileMenu PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") # works for all build modes<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Building_on_Windows
Building on Windows
2012-09-16T17:42:53Z
<p>Daviddoria: Created page with 'A typical CMakeLists.txt file on this site looks like this: <source lang="cmake"> cmake_minimum_required(VERSION 2.6) PROJECT(FileMenu) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_…'</p>
<hr />
<div>A typical CMakeLists.txt file on this site looks like this:<br />
<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
PROJECT(FileMenu)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs main.ui)<br />
QT4_WRAP_CPP(MOCSrcs filemenu.h)<br />
<br />
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(FileMenu main.cpp filemenu.h filemenu.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(FileMenu ${QT_LIBRARIES})<br />
</source><br />
<br />
However, when you build and run in Windows, you will get a console window that appears along with your GUI program. To fix this, you must do two things. First, add ${QT_QTMAIN_LIBRARY} to your target_link_libraries command. Second, you must specify /SUBSYSTEM:WINDOWS for all build configurations (Release, Debug, etc) that you want to not pop up the console window. An example is below, where when built in release mode, no console will appear:<br />
<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(FileMenu)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs main.ui)<br />
QT4_WRAP_CPP(MOCSrcs filemenu.h)<br />
<br />
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(FileMenu main.cpp filemenu.h filemenu.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(FileMenu ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})<br />
<br />
set_target_properties(FileMenu PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Qt
Qt
2012-09-16T17:39:28Z
<p>Daviddoria: </p>
<hr />
<div>== Building ==<br />
* [[Building on Windows]]<br />
<br />
== Simple Widgets ==<br />
* [[Qt/AutoConnect|Auto connect slots]]<br />
* [[Qt/ToolbarIcons|Toolbar icons]]<br />
* [[Qt/Icons|Use icons without resources (QCommonStyle) - Old method]]<br />
* [[Qt/Toolbar|Display a toolbar (also an example of resources)]]<br />
* [[Qt/Dialog|Display a dialog]]<br />
* [[Qt/ProgrammaticButton|Programmatically create a button]]<br />
* [[Qt/ButtonWidget|Button widget (single inheritance)]]<br />
* [[Qt/ButtonWidgetMultipleInheritance|Button widget (multiple inheritance)]]<br />
* [[Qt/CallANormalFunction|Call a normal function from an event]]<br />
* [[Qt/Widgets/CheckBox|Check box widget]]<br />
* [[Qt/Widgets/ComboBox|Combo box widget]]<br />
* [[Qt/Widgets/ProgressBar|Progress bar widget]]<br />
* [[Qt/Widgets/ProgressBarMarquee|Progress bar marquee widget]]<br />
* [[Qt/Widgets/ProgressThreaded|Display a progress bar while a long operation is being processed]]<br />
* [[Qt/Widgets/Slider|Slider widget]]<br />
* [[Qt/Widgets/FileDialog|File dialog]]<br />
* [[Qt/Widgets/FileDialogDefaultSuffix|File dialog - append a specified suffix if one is not provided]]<br />
* [[Qt/Widgets/RadioButton|Radio button widget]]<br />
* [[Qt/Widgets/Timer|Timer]]<br />
* [[Qt/Widgets/Thread|Thread]]<br />
* [[Qt/Widgets/MessageBoxFromThread|MessageBox from a thread]]<br />
* [[Qt/Widgets/ThreadClassMessageBox|MessageBox from a class object within a thread]]<br />
* [[Qt/Widgets/QWidgetSubclass|QWidget subclass in a cpp file]]<br />
* [[Qt/File|Operations on files (exist, etc)]]<br />
* [[Qt/FileInfo|Information about a file (basename, path, extension, etc)]]<br />
* [[Qt/Widgets/FileMenu|File menu]]<br />
* [[Qt/Widgets/WidgetInsideMainWindow|Display a widget inside a main window]]<br />
* [[Qt/Widgets/WidgetTemplated|Display a templated widget inside a main window]]<br />
* [[Qt/Widgets/Cursor|Change the cursor]]<br />
* [[Qt/Widgets/LineEdit|LineEdit widget - a text box]]<br />
* [[Qt/Widgets/Label|Label]]<br />
<br />
== Model/View ==<br />
* [[Qt/ModelView/QAbstractTableModel|QAbstractTableModel]]<br />
* [[Qt/ModelView/ComboBoxOfCheckBoxes|ComboBox of CheckBoxes (QStandardItemModel, QStandardItem)]]<br />
* [[Qt/ModelView/StringListModelCheckable|A StringListModel with checkboxes]]<br />
* [[Qt/ModelView/StandardItemModel|A StandardItemModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelCheckable|An AbstractListModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelFileDialog|An AbstractListModel where one of the cells can be changed using a QFileDialog]]<br />
* [[Qt/ModelView/ListViewComboBox|A persistent ComboBox on a list view]]<br />
* [[Qt/ModelView/ItemSelectionModel|Track selected items in a model]]<br />
<br />
* [[Qt/ModelView/AbstractTableModelCheckable|A table with checkboxes]]<br />
<br />
== Utilities ==<br />
* [[Qt/Widgets/Time|Get the system time]]<br />
* [[Qt/Utilities/StatusBar|Status bar]]<br />
* [[Qt/Utilities/DragAndDropFiles|Drag and drop files onto a widget]]<br />
* [[Qt/Utilities/HandleItem|Add resize handles to a rectangle]]<br />
* [[Qt/Utilities/EventFilter|Handle another widgets event]]<br />
<br />
== Other ==<br />
* [[Qt/Boost|Using Qt with Boost]]<br />
<br />
== Images ==<br />
* [[Qt/Images/Pixmap|QPixmap]]<br />
<br />
* [[Qt/Images/MovingAPixmap|Move a pixmap in a QGraphicsView]]<br />
<br />
* [[Qt/Images/SemiTransparentPixels|Make pixels semi-transparent]]<br />
<br />
* [[Qt/Images/RubberBand|Use a QRubberBand to indicate a selected region in an image]]<br />
<br />
* [[Qt/Images/RubberBandSignal|Customize QGraphicsView to monitor the RubberBand behavior]]<br />
<br />
== Delegates ==<br />
* [[Qt/Delegates/ComboBoxDelegate|A combobox in a TableView]]<br />
<br />
== Databases ==<br />
* [[Qt/Databases/ListView|A ListView of a table column]]<br />
<br />
== QWT ==<br />
* [[Qt/QWT/Plot|Simple plot]]<br />
<br />
== Events ==<br />
* [[Qt/Events/Resize|Resize a graphics item when the form is resized]]</div>
Daviddoria
http://programmingexamples.net/wiki/Qt/Widgets/FileMenu
Qt/Widgets/FileMenu
2012-09-16T16:52:33Z
<p>Daviddoria: /* filemenu.h */</p>
<hr />
<div>==main.cpp==<br />
<source lang="cpp"><br />
#include <QApplication><br />
<br />
#include "filemenu.h"<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
MyForm form;<br />
<br />
form.show();<br />
return app.exec();<br />
}<br />
<br />
<br />
</source><br />
<br />
==filemenu.cpp==<br />
<source lang="cpp"><br />
#include "filemenu.h"<br />
<br />
#include <iostream><br />
<br />
MyForm::MyForm(QWidget *parent)<br />
{<br />
setupUi(this);<br />
connect( this->mnuTest, SIGNAL( triggered() ), this, SLOT(mnuTest_triggered()) );<br />
}<br />
<br />
void MyForm::mnuTest_triggered()<br />
{<br />
std::cout << "Clicked." << std::endl;<br />
}<br />
<br />
</source><br />
<br />
==filemenu.h==<br />
<source lang="cpp"><br />
#ifndef FILEMENUFORM_H<br />
#define FILEMENUFORM_H<br />
<br />
#include "ui_main.h"<br />
<br />
class MyForm : public QMainWindow, private Ui::FileMenuForm<br />
{<br />
Q_OBJECT<br />
public:<br />
MyForm(QWidget *parent = 0);<br />
<br />
public slots:<br />
void mnuTest_triggered();<br />
};<br />
<br />
#endif<br />
<br />
</source><br />
<br />
==main.ui==<br />
<source lang="text"><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<ui version="4.0"><br />
<class>FileMenuForm</class><br />
<widget class="QMainWindow" name="FileMenuForm"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>800</width><br />
<height>600</height><br />
</rect><br />
</property><br />
<property name="windowTitle"><br />
<string>Test</string><br />
</property><br />
<widget class="QWidget" name="centralwidget"/><br />
<widget class="QMenuBar" name="menubar"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>800</width><br />
<height>24</height><br />
</rect><br />
</property><br />
<widget class="QMenu" name="menuFile"><br />
<property name="title"><br />
<string>File</string><br />
</property><br />
<addaction name="mnuTest"/><br />
</widget><br />
<addaction name="menuFile"/><br />
</widget><br />
<widget class="QStatusBar" name="statusbar"/><br />
<action name="mnuTest"><br />
<property name="text"><br />
<string>Test</string><br />
</property><br />
</action><br />
</widget><br />
<resources/><br />
<connections/><br />
</ui><br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(FileMenu)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs main.ui)<br />
QT4_WRAP_CPP(MOCSrcs filemenu.h)<br />
<br />
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(FileMenu main.cpp filemenu.h filemenu.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(FileMenu ${QT_LIBRARIES})<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Qt/Widgets/FileMenu
Qt/Widgets/FileMenu
2012-09-16T16:22:15Z
<p>Daviddoria: </p>
<hr />
<div>==main.cpp==<br />
<source lang="cpp"><br />
#include <QApplication><br />
<br />
#include "filemenu.h"<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
MyForm form;<br />
<br />
form.show();<br />
return app.exec();<br />
}<br />
<br />
<br />
</source><br />
<br />
==filemenu.cpp==<br />
<source lang="cpp"><br />
#include "filemenu.h"<br />
<br />
#include <iostream><br />
<br />
MyForm::MyForm(QWidget *parent)<br />
{<br />
setupUi(this);<br />
connect( this->mnuTest, SIGNAL( triggered() ), this, SLOT(mnuTest_triggered()) );<br />
}<br />
<br />
void MyForm::mnuTest_triggered()<br />
{<br />
std::cout << "Clicked." << std::endl;<br />
}<br />
<br />
</source><br />
<br />
==filemenu.h==<br />
<source lang="cpp"><br />
#ifndef FILEMENUFORM_H<br />
#define FILEMENUFORM_H<br />
<br />
#include "ui_form.h"<br />
<br />
class MyForm : public QMainWindow, private Ui::FileMenuForm<br />
{<br />
Q_OBJECT<br />
public:<br />
MyForm(QWidget *parent = 0);<br />
<br />
public slots:<br />
void mnuTest_triggered();<br />
};<br />
<br />
#endif<br />
<br />
</source><br />
<br />
==main.ui==<br />
<source lang="text"><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<ui version="4.0"><br />
<class>FileMenuForm</class><br />
<widget class="QMainWindow" name="FileMenuForm"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>800</width><br />
<height>600</height><br />
</rect><br />
</property><br />
<property name="windowTitle"><br />
<string>Test</string><br />
</property><br />
<widget class="QWidget" name="centralwidget"/><br />
<widget class="QMenuBar" name="menubar"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>800</width><br />
<height>24</height><br />
</rect><br />
</property><br />
<widget class="QMenu" name="menuFile"><br />
<property name="title"><br />
<string>File</string><br />
</property><br />
<addaction name="mnuTest"/><br />
</widget><br />
<addaction name="menuFile"/><br />
</widget><br />
<widget class="QStatusBar" name="statusbar"/><br />
<action name="mnuTest"><br />
<property name="text"><br />
<string>Test</string><br />
</property><br />
</action><br />
</widget><br />
<resources/><br />
<connections/><br />
</ui><br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(FileMenu)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs main.ui)<br />
QT4_WRAP_CPP(MOCSrcs filemenu.h)<br />
<br />
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(FileMenu main.cpp filemenu.h filemenu.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(FileMenu ${QT_LIBRARIES})<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/User_talk:Nelson_Barata
User talk:Nelson Barata
2012-09-12T14:08:33Z
<p>Daviddoria: </p>
<hr />
<div>'''Welcome to ''ProgrammingExamples''!'''<br />
We hope you will contribute much and well. <br />
You will probably want to read the [[Help:Contents|help pages]].<br />
Again, welcome and have fun! [[User:Daviddoria|Daviddoria]] 13:55, 12 September 2012 (UTC)<br />
<br />
Hi Nelson! Thanks for your first contribution!! Could I ask you to leave a brief not in the "Summary" of the changes/additions you make? This way when I come along and check them out, I can see "ah, it is better to create the object on the heap instead of pass the address of an object on the stack because...". Keep the contributions coming! [[User:Daviddoria|Daviddoria]] 14:08, 12 September 2012 (UTC)</div>
Daviddoria
http://programmingexamples.net/wiki/Qt/Events/Resize
Qt/Events/Resize
2012-09-12T13:58:57Z
<p>Daviddoria: </p>
<hr />
<div>==main.cpp==<br />
<source lang="cpp"><br />
#include <QApplication><br />
<br />
#include "form.h"<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
Form form;<br />
<br />
form.show();<br />
return app.exec();<br />
}<br />
<br />
</source><br />
<br />
==form.h==<br />
<source lang="cpp"><br />
#ifndef FORM_H<br />
#define FORM_H<br />
<br />
#include "ui_form.h"<br />
<br />
class QGraphicsPixmapItem;<br />
<br />
class Form : public QWidget, public Ui::Form<br />
{<br />
Q_OBJECT<br />
<br />
public:<br />
Form(QWidget *parent = 0);<br />
protected:<br />
<br />
void resizeEvent ( QResizeEvent * event );<br />
<br />
QGraphicsPixmapItem* BlackItem;<br />
};<br />
<br />
#endif<br />
</source><br />
<br />
==form.cpp==<br />
<source lang="cpp"><br />
#include <QtGui><br />
<br />
#include <iostream><br />
<br />
#include "form.h"<br />
<br />
Form::Form(QWidget *parent) : QWidget(parent)<br />
{<br />
this->setupUi(this);<br />
<br />
QGraphicsScene* scene = new QGraphicsScene;<br />
<br />
//// Add a qpixmap to the scene.<br />
QPixmap pixmap(40, 40);<br />
QColor black(0,0,0);<br />
pixmap.fill(black);<br />
this->BlackItem = scene->addPixmap(pixmap);<br />
//this->graphicsView->fitInView(blackItem);<br />
<br />
//Add another qpixmap to the scene. Drag one of them around and watch the scene change.<br />
QPixmap pixmap2(30, 30);<br />
QColor red(255,0,0);<br />
pixmap2.fill(red);<br />
QGraphicsPixmapItem * redItem = scene->addPixmap(pixmap2);<br />
redItem->setFlag(QGraphicsItem::ItemIsMovable);<br />
<br />
scene->setSceneRect(pixmap.rect());<br />
this->graphicsView->setScene(scene);<br />
}<br />
<br />
void Form::resizeEvent ( QResizeEvent * event )<br />
{<br />
std::cout << "ResizeEvent" << std::endl;<br />
this->graphicsView->fitInView(this->BlackItem);<br />
}<br />
<br />
</source><br />
<br />
==form.ui==<br />
<source lang="text"><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<ui version="4.0"><br />
<class>Form</class><br />
<widget class="QWidget" name="Form"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>312</width><br />
<height>243</height><br />
</rect><br />
</property><br />
<property name="windowTitle"><br />
<string>Form</string><br />
</property><br />
<layout class="QGridLayout" name="gridLayout"><br />
<item row="0" column="0"><br />
<widget class="QGraphicsView" name="graphicsView"><br />
<property name="backgroundBrush"><br />
<brush brushstyle="NoBrush"><br />
<color alpha="255"><br />
<red>0</red><br />
<green>0</green><br />
<blue>0</blue><br />
</color><br />
</brush><br />
</property><br />
</widget><br />
</item><br />
</layout><br />
</widget><br />
<resources/><br />
<connections/><br />
</ui><br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(ResizeEvent)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs form.ui)<br />
QT4_WRAP_CPP(MOCSrcs form.h)<br />
<br />
include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(ResizeEvent main.cpp form.h form.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(ResizeEvent ${QT_LIBRARIES})<br />
<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Qt/Events/Resize
Qt/Events/Resize
2012-09-12T13:58:35Z
<p>Daviddoria: Created page with '==main.cpp== <source lang="cpp"> #include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Form form; form.sho…'</p>
<hr />
<div>==main.cpp==<br />
<source lang="cpp"><br />
#include <QApplication><br />
<br />
#include "form.h"<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
Form form;<br />
<br />
form.show();<br />
return app.exec();<br />
}<br />
<br />
</source><br />
<br />
==form.h==<br />
</source><br />
#ifndef FORM_H<br />
#define FORM_H<br />
<br />
#include "ui_form.h"<br />
<br />
class QGraphicsPixmapItem;<br />
<br />
class Form : public QWidget, public Ui::Form<br />
{<br />
Q_OBJECT<br />
<br />
public:<br />
Form(QWidget *parent = 0);<br />
protected:<br />
<br />
void resizeEvent ( QResizeEvent * event );<br />
<br />
QGraphicsPixmapItem* BlackItem;<br />
};<br />
<br />
#endif<br />
</source><br />
<br />
==form.cpp==<br />
<source lang="cpp"><br />
#include <QtGui><br />
<br />
#include <iostream><br />
<br />
#include "form.h"<br />
<br />
Form::Form(QWidget *parent) : QWidget(parent)<br />
{<br />
this->setupUi(this);<br />
<br />
QGraphicsScene* scene = new QGraphicsScene;<br />
<br />
//// Add a qpixmap to the scene.<br />
QPixmap pixmap(40, 40);<br />
QColor black(0,0,0);<br />
pixmap.fill(black);<br />
this->BlackItem = scene->addPixmap(pixmap);<br />
//this->graphicsView->fitInView(blackItem);<br />
<br />
//Add another qpixmap to the scene. Drag one of them around and watch the scene change.<br />
QPixmap pixmap2(30, 30);<br />
QColor red(255,0,0);<br />
pixmap2.fill(red);<br />
QGraphicsPixmapItem * redItem = scene->addPixmap(pixmap2);<br />
redItem->setFlag(QGraphicsItem::ItemIsMovable);<br />
<br />
scene->setSceneRect(pixmap.rect());<br />
this->graphicsView->setScene(scene);<br />
}<br />
<br />
void Form::resizeEvent ( QResizeEvent * event )<br />
{<br />
std::cout << "ResizeEvent" << std::endl;<br />
this->graphicsView->fitInView(this->BlackItem);<br />
}<br />
<br />
</source><br />
<br />
==form.ui==<br />
<source lang="text"><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<ui version="4.0"><br />
<class>Form</class><br />
<widget class="QWidget" name="Form"><br />
<property name="geometry"><br />
<rect><br />
<x>0</x><br />
<y>0</y><br />
<width>312</width><br />
<height>243</height><br />
</rect><br />
</property><br />
<property name="windowTitle"><br />
<string>Form</string><br />
</property><br />
<layout class="QGridLayout" name="gridLayout"><br />
<item row="0" column="0"><br />
<widget class="QGraphicsView" name="graphicsView"><br />
<property name="backgroundBrush"><br />
<brush brushstyle="NoBrush"><br />
<color alpha="255"><br />
<red>0</red><br />
<green>0</green><br />
<blue>0</blue><br />
</color><br />
</brush><br />
</property><br />
</widget><br />
</item><br />
</layout><br />
</widget><br />
<resources/><br />
<connections/><br />
</ui><br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
PROJECT(ResizeEvent)<br />
<br />
FIND_PACKAGE(Qt4 REQUIRED)<br />
INCLUDE(${QT_USE_FILE})<br />
<br />
QT4_WRAP_UI(UISrcs form.ui)<br />
QT4_WRAP_CPP(MOCSrcs form.h)<br />
<br />
include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})<br />
<br />
ADD_EXECUTABLE(ResizeEvent main.cpp form.h form.cpp ${MOCSrcs} ${UISrcs})<br />
TARGET_LINK_LIBRARIES(ResizeEvent ${QT_LIBRARIES})<br />
<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/Qt
Qt
2012-09-12T13:57:01Z
<p>Daviddoria: </p>
<hr />
<div>== Simple Widgets ==<br />
* [[Qt/AutoConnect|Auto connect slots]]<br />
* [[Qt/ToolbarIcons|Toolbar icons]]<br />
* [[Qt/Icons|Use icons without resources (QCommonStyle) - Old method]]<br />
* [[Qt/Toolbar|Display a toolbar (also an example of resources)]]<br />
* [[Qt/Dialog|Display a dialog]]<br />
* [[Qt/ProgrammaticButton|Programmatically create a button]]<br />
* [[Qt/ButtonWidget|Button widget (single inheritance)]]<br />
* [[Qt/ButtonWidgetMultipleInheritance|Button widget (multiple inheritance)]]<br />
* [[Qt/CallANormalFunction|Call a normal function from an event]]<br />
* [[Qt/Widgets/CheckBox|Check box widget]]<br />
* [[Qt/Widgets/ComboBox|Combo box widget]]<br />
* [[Qt/Widgets/ProgressBar|Progress bar widget]]<br />
* [[Qt/Widgets/ProgressBarMarquee|Progress bar marquee widget]]<br />
* [[Qt/Widgets/ProgressThreaded|Display a progress bar while a long operation is being processed]]<br />
* [[Qt/Widgets/Slider|Slider widget]]<br />
* [[Qt/Widgets/FileDialog|File dialog]]<br />
* [[Qt/Widgets/FileDialogDefaultSuffix|File dialog - append a specified suffix if one is not provided]]<br />
* [[Qt/Widgets/RadioButton|Radio button widget]]<br />
* [[Qt/Widgets/Timer|Timer]]<br />
* [[Qt/Widgets/Thread|Thread]]<br />
* [[Qt/Widgets/MessageBoxFromThread|MessageBox from a thread]]<br />
* [[Qt/Widgets/ThreadClassMessageBox|MessageBox from a class object within a thread]]<br />
* [[Qt/Widgets/QWidgetSubclass|QWidget subclass in a cpp file]]<br />
* [[Qt/File|Operations on files (exist, etc)]]<br />
* [[Qt/FileInfo|Information about a file (basename, path, extension, etc)]]<br />
* [[Qt/Widgets/FileMenu|File menu]]<br />
* [[Qt/Widgets/WidgetInsideMainWindow|Display a widget inside a main window]]<br />
* [[Qt/Widgets/WidgetTemplated|Display a templated widget inside a main window]]<br />
* [[Qt/Widgets/Cursor|Change the cursor]]<br />
* [[Qt/Widgets/LineEdit|LineEdit widget - a text box]]<br />
* [[Qt/Widgets/Label|Label]]<br />
<br />
== Model/View ==<br />
* [[Qt/ModelView/QAbstractTableModel|QAbstractTableModel]]<br />
* [[Qt/ModelView/ComboBoxOfCheckBoxes|ComboBox of CheckBoxes (QStandardItemModel, QStandardItem)]]<br />
* [[Qt/ModelView/StringListModelCheckable|A StringListModel with checkboxes]]<br />
* [[Qt/ModelView/StandardItemModel|A StandardItemModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelCheckable|An AbstractListModel with checkboxes]]<br />
* [[Qt/ModelView/AbstractListModelFileDialog|An AbstractListModel where one of the cells can be changed using a QFileDialog]]<br />
* [[Qt/ModelView/ListViewComboBox|A persistent ComboBox on a list view]]<br />
* [[Qt/ModelView/ItemSelectionModel|Track selected items in a model]]<br />
<br />
* [[Qt/ModelView/AbstractTableModelCheckable|A table with checkboxes]]<br />
<br />
== Utilities ==<br />
* [[Qt/Widgets/Time|Get the system time]]<br />
* [[Qt/Utilities/StatusBar|Status bar]]<br />
* [[Qt/Utilities/DragAndDropFiles|Drag and drop files onto a widget]]<br />
* [[Qt/Utilities/HandleItem|Add resize handles to a rectangle]]<br />
* [[Qt/Utilities/EventFilter|Handle another widgets event]]<br />
<br />
== Other ==<br />
* [[Qt/Boost|Using Qt with Boost]]<br />
<br />
== Images ==<br />
* [[Qt/Images/Pixmap|QPixmap]]<br />
<br />
* [[Qt/Images/MovingAPixmap|Move a pixmap in a QGraphicsView]]<br />
<br />
* [[Qt/Images/SemiTransparentPixels|Make pixels semi-transparent]]<br />
<br />
* [[Qt/Images/RubberBand|Use a QRubberBand to indicate a selected region in an image]]<br />
<br />
* [[Qt/Images/RubberBandSignal|Customize QGraphicsView to monitor the RubberBand behavior]]<br />
<br />
== Delegates ==<br />
* [[Qt/Delegates/ComboBoxDelegate|A combobox in a TableView]]<br />
<br />
== Databases ==<br />
* [[Qt/Databases/ListView|A ListView of a table column]]<br />
<br />
== QWT ==<br />
* [[Qt/QWT/Plot|Simple plot]]<br />
<br />
== Events ==<br />
* [[Qt/Events/Resize|Resize a graphics item when the form is resized]]</div>
Daviddoria
http://programmingexamples.net/wiki/User:Nelson_Barata
User:Nelson Barata
2012-09-12T13:55:10Z
<p>Daviddoria: Creating user page with biography of new user.</p>
<hr />
<div>I am a french IT engineer for 12 years.<br />
I started using Qt 6 years ago.<br />
My main activities cover embedded system (bare or with OSs) and graphical tools running in windows or linux.<br />
My main programming languages are C and C++, I have some expérience in Java and other languages.</div>
Daviddoria
http://programmingexamples.net/wiki/User_talk:Nelson_Barata
User talk:Nelson Barata
2012-09-12T13:55:10Z
<p>Daviddoria: Welcome!</p>
<hr />
<div>'''Welcome to ''ProgrammingExamples''!'''<br />
We hope you will contribute much and well. <br />
You will probably want to read the [[Help:Contents|help pages]].<br />
Again, welcome and have fun! [[User:Daviddoria|Daviddoria]] 13:55, 12 September 2012 (UTC)</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/Heap/IndirectCompare
CPP/Boost/Heap/IndirectCompare
2012-09-05T21:35:05Z
<p>Daviddoria: Created page with '<syntaxhighlight lang="cpp"> #include <boost/heap/binomial_heap.hpp> #include <boost/pending/indirect_cmp.hpp> #include <boost/array.hpp> #include <boost/graph/grid_graph.hpp> #i…'</p>
<hr />
<div><syntaxhighlight lang="cpp"><br />
#include <boost/heap/binomial_heap.hpp><br />
#include <boost/pending/indirect_cmp.hpp><br />
#include <boost/array.hpp><br />
#include <boost/graph/grid_graph.hpp><br />
#include <iostream><br />
<br />
int main(int, char*[])<br />
{<br />
boost::array<std::size_t, 2> lengths = { { 2,2 } };<br />
typedef boost::grid_graph<2> GraphType;<br />
GraphType graph(lengths);<br />
typedef boost::graph_traits<GraphType>::vertex_descriptor Vertex;<br />
typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type GridIndexMapType;<br />
GridIndexMapType gridIndexMap(get(boost::vertex_index, graph));<br />
<br />
typedef boost::graph_traits<GraphType>::vertex_iterator VertexIteratorType;<br />
VertexIteratorType vertexIterator, vertexIteratorEnd;<br />
<br />
typedef boost::vector_property_map<float, GridIndexMapType> PriorityMapType;<br />
PriorityMapType priorityMap(gridIndexMap);<br />
<br />
typedef boost::indirect_cmp<PriorityMapType, std::less<float> > IndirectComparisonType;<br />
IndirectComparisonType indirectComparison(priorityMap);<br />
<br />
typedef boost::heap::binomial_heap<Vertex, boost::heap::stable<false>, boost::heap::compare<IndirectComparisonType> > PriorityQueueType;<br />
PriorityQueueType pq(indirectComparison);<br />
<br />
typedef typename PriorityQueueType::handle_type handle_t;<br />
<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
put(priorityMap, *vertexIterator, rand() % 1000);<br />
pq.push(*vertexIterator);<br />
}<br />
<br />
// Change all of the priorities in the map<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
put(priorityMap, *vertexIterator, rand() % 1000);<br />
}<br />
<br />
// Resort the queue<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
// pq.update(handle3, 5);<br />
}<br />
<br />
// Output the final queue<br />
while(!pq.empty())<br />
{<br />
Vertex v = pq.top();<br />
std::cout << v[0] << " " << v[1] << std::endl;<br />
pq.pop();<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
</syntaxhighlight></div>
Daviddoria
http://programmingexamples.net/wiki/Boost
Boost
2012-09-05T21:34:13Z
<p>Daviddoria: /* Boost Math Library */</p>
<hr />
<div>The following examples are frequent use cases of parts of the Boost (http://www.boost.org/) library. Each example includes a CMakeLists.txt file so it can be easily compiled.<br />
<br />
== Boost Examples ==<br />
* [[CPP/Boost/LexicalCast|lexical_cast - a replacement for std::stringstream]]<br />
* [[CPP/Boost/Bimap|Bidirectional (both ways) map]]<br />
* [[CPP/Boost/Function|Glorified function pointers (function.hpp and bind.hpp)]]<br />
* [[CPP/Boost/Histogram|Create a histogram (accumulator)]]<br />
* [[CPP/Boost/Numeric/Matrix|Matrix]]<br />
* [[CPP/Boost/Numeric/MultiArray|Multi dimensional array]]<br />
* [[CPP/Boost/ProgramOptions/Simple|Simple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgramOptions/MultipleArguments|Multiple command line argument parsing (ProgramOptions)]]<br />
* [[CPP/Boost/ProgressBar|ProgressBar]]<br />
* [[CPP/Boost/Threads|Threads]]<br />
* [[CPP/Boost/ThreadsMember|Threads with member functions]]<br />
* [[CPP/Boost/ThreadCommunication|ThreadCommunication]]<br />
* [[CPP/Boost/Timer|Timer]]<br />
* [[CPP/Boost/Signals/Basic|Signal/slot pattern]]<br />
* [[CPP/Boost/Signals/Class|Signal/slot pattern with member functions]]<br />
* [[CPP/Boost/Signals/ClassMember|Signal/slot pattern with member classes]]<br />
* [[CPP/Boost/Signals/ClassMemberWithParameters|Signal/slot pattern with member classes which have parameters]]<br />
* [[CPP/Boost/Signals2/Basic|Signals2: Signal/slot pattern with type safety]]<br />
* [[CPP/Boost/Signals2/Parameters|Signals2: Signal/slot pattern with parameters type safety]]<br />
<br />
== Boost Graph Library (BGL) ==<br />
The Boost Graph Library is a c++ library for graph theoretic data structures and algorithms. There are several examples here: [[Boost/BGL|Boost Graph Library Examples]]<br />
<br />
=== Wish List ===<br />
Examples in this section are either shells or something is wrong with them that must be fixed before they can graduate into real examples.<br />
<br />
== Boost (Generic) Geometry Library ==<br />
* [[CPP/Boost/Geometry/DistanceBetweenPoints|Compute the distance between two points]]<br />
* [[CPP/Boost/Geometry/PointInPolygon|Determine if a point is inside of a polygon (within() function)]]<br />
* [[CPP/Boost/Geometry/Simplify|Simplify a polyline]]<br />
<br />
== Boost Iterators ==<br />
* [[CPP/Boost/Iterators/IndirectIterator|Access a collection of pointers as if it were a collection of objects]]<br />
<br />
== Boost Math Library ==<br />
=== uBLAS ===<br />
* [[CPP/Boost/Math/uBLAS/determinant]] Calculating the determinant of a matrix using boost::numeric::lu_factorize<br />
=== Tools ===<br />
* [[CPP/Boost/Math/Tools/brent_find_minima|brent_find_minima]] Find a bracketed minimum of a function<br />
* [[CPP/Boost/Math/Tools/TOMS748|TOMS748 root finding algorithm]] Find a bracketed root(zero) of a function<br />
<br />
== Heap ==<br />
* [[CPP/Boost/Heap/IndirectCompare|Indirect heap]] Sort a heap by values in a property map</div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/BGL/IndirectPriorityQueue
CPP/Boost/BGL/IndirectPriorityQueue
2012-09-03T14:51:20Z
<p>Daviddoria: </p>
<hr />
<div>==IndirectPriorityQueue.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
<br />
#include <boost/graph/grid_graph.hpp><br />
#include <boost/graph/detail/d_ary_heap.hpp><br />
#include <boost/property_map/property_map.hpp><br />
<br />
#include <cstdlib><br />
<br />
template <typename TQueue><br />
static void OutputQueue(TQueue queue);<br />
<br />
int main(int, char*[])<br />
{<br />
srand((unsigned int)time(NULL));<br />
<br />
boost::array<std::size_t, 2> lengths = { { 5,5 } };<br />
typedef boost::grid_graph<2> GraphType;<br />
GraphType graph(lengths);<br />
typedef boost::graph_traits<GraphType>::vertex_descriptor Vertex;<br />
typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type GridIndexMapType;<br />
GridIndexMapType gridIndexMap(get(boost::vertex_index, graph));<br />
<br />
typedef boost::vector_property_map<std::size_t, GridIndexMapType> IndexInHeapMap;<br />
IndexInHeapMap index_in_heap(gridIndexMap);<br />
<br />
typedef boost::graph_traits<GraphType>::vertex_iterator VertexIteratorType;<br />
<br />
typedef boost::vector_property_map<float, GridIndexMapType> PriorityMapType;<br />
PriorityMapType priorityMap(gridIndexMap);<br />
VertexIteratorType vertexIterator, vertexIteratorEnd;<br />
<br />
typedef std::greater<float> ComparisonFunctor;<br />
typedef boost::d_ary_heap_indirect<Vertex, 4, IndexInHeapMap, PriorityMapType, ComparisonFunctor > MutableQueueType;<br />
<br />
ComparisonFunctor comparisonFunctor;<br />
MutableQueueType mutableQueue(priorityMap, index_in_heap, comparisonFunctor);<br />
<br />
std::cout << "There are " << mutableQueue.size() << " items in the queue." << std::endl;<br />
<br />
// Add random values to the vertices and add them to the queue<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
put(priorityMap, *vertexIterator, rand() % 1000);<br />
}<br />
<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
mutableQueue.push(*vertexIterator);<br />
}<br />
<br />
std::cout << "There are " << mutableQueue.size() << " items in the queue." << std::endl;<br />
<br />
std::cout << "The priority queue is: " << std::endl;<br />
OutputQueue(mutableQueue);<br />
<br />
// Insert another set of random values for each vertex<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
put(priorityMap, *vertexIterator, rand() % 1000);<br />
}<br />
<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
mutableQueue.push(*vertexIterator);<br />
}<br />
<br />
std::cout << "There are " << mutableQueue.size() << " items in the queue." << std::endl;<br />
<br />
std::cout << "The priority queue is: " << std::endl;<br />
OutputQueue(mutableQueue);<br />
<br />
std::cout << std::endl;<br />
<br />
return 0;<br />
}<br />
<br />
template <typename TQueue><br />
static void OutputQueue(TQueue queue)<br />
{<br />
while( ! queue.empty() )<br />
{<br />
typename TQueue::value_type u = queue.top();<br />
<br />
// These two lines are equivalent<br />
std::cout << "vertex: " << u[0] << " " << u[1] << " priority: " << get(queue.keys(), u) << std::endl;<br />
<br />
queue.pop();<br />
}<br />
}<br />
<br />
/* Output:<br />
There are 0 items in the queue.<br />
There are 25 items in the queue.<br />
The priority queue is: <br />
vertex: 4 3 priority: 989<br />
vertex: 3 2 priority: 976<br />
vertex: 0 1 priority: 937<br />
vertex: 1 4 priority: 824<br />
vertex: 0 2 priority: 805<br />
vertex: 1 0 priority: 770<br />
vertex: 4 2 priority: 770<br />
vertex: 4 4 priority: 733<br />
vertex: 2 2 priority: 623<br />
vertex: 0 4 priority: 566<br />
vertex: 3 0 priority: 513<br />
vertex: 4 0 priority: 494<br />
vertex: 2 3 priority: 418<br />
vertex: 3 1 priority: 411<br />
vertex: 1 1 priority: 408<br />
vertex: 0 3 priority: 378<br />
vertex: 3 3 priority: 300<br />
vertex: 3 4 priority: 286<br />
vertex: 0 0 priority: 206<br />
vertex: 2 1 priority: 198<br />
vertex: 1 2 priority: 159<br />
vertex: 2 0 priority: 157<br />
vertex: 2 4 priority: 108<br />
vertex: 1 3 priority: 103<br />
vertex: 4 1 priority: 5<br />
There are 50 items in the queue.<br />
The priority queue is: <br />
vertex: 3 0 priority: 998<br />
vertex: 3 2 priority: 979<br />
vertex: 3 2 priority: 979<br />
vertex: 2 4 priority: 920<br />
vertex: 0 1 priority: 853<br />
vertex: 0 1 priority: 853<br />
vertex: 3 0 priority: 998<br />
vertex: 4 4 priority: 842<br />
vertex: 2 2 priority: 830<br />
vertex: 2 2 priority: 830<br />
vertex: 3 3 priority: 811<br />
vertex: 3 3 priority: 811<br />
vertex: 0 2 priority: 781<br />
vertex: 0 2 priority: 781<br />
vertex: 1 1 priority: 556<br />
vertex: 4 0 priority: 517<br />
vertex: 4 0 priority: 517<br />
vertex: 4 3 priority: 464<br />
vertex: 4 3 priority: 464<br />
vertex: 3 1 priority: 363<br />
vertex: 3 1 priority: 363<br />
vertex: 0 4 priority: 345<br />
vertex: 1 1 priority: 556<br />
vertex: 0 4 priority: 345<br />
vertex: 1 2 priority: 300<br />
vertex: 1 2 priority: 300<br />
vertex: 4 4 priority: 842<br />
vertex: 2 1 priority: 287<br />
vertex: 2 1 priority: 287<br />
vertex: 2 3 priority: 222<br />
vertex: 2 3 priority: 222<br />
vertex: 1 0 priority: 197<br />
vertex: 2 4 priority: 920<br />
vertex: 1 0 priority: 197<br />
vertex: 1 4 priority: 189<br />
vertex: 1 4 priority: 189<br />
vertex: 0 3 priority: 187<br />
vertex: 0 3 priority: 187<br />
vertex: 1 3 priority: 136<br />
vertex: 1 3 priority: 136<br />
vertex: 0 0 priority: 119<br />
vertex: 0 0 priority: 119<br />
vertex: 2 0 priority: 118<br />
vertex: 2 0 priority: 118<br />
vertex: 3 4 priority: 115<br />
vertex: 3 4 priority: 115<br />
vertex: 4 1 priority: 70<br />
vertex: 4 1 priority: 70<br />
vertex: 4 2 priority: 63<br />
vertex: 4 2 priority: 63<br />
<br />
*/<br />
<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(IndirectPriorityQueue)<br />
<br />
set(Boost_USE_MULTITHREADED ON)<br />
FIND_PACKAGE(Boost 1.38 COMPONENTS)<br />
<br />
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})<br />
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})<br />
<br />
ADD_EXECUTABLE(IndirectPriorityQueue IndirectPriorityQueue.cpp)<br />
<br />
</source></div>
Daviddoria
http://programmingexamples.net/wiki/CPP/Boost/BGL/IndirectPriorityQueue
CPP/Boost/BGL/IndirectPriorityQueue
2012-09-03T14:42:45Z
<p>Daviddoria: Created page with '==IndirectPriorityQueue.cpp== <source lang="cpp"> #include <iostream> #include <iomanip> #include <boost/graph/grid_graph.hpp> #include <boost/graph/detail/d_ary_heap.hpp> #incl…'</p>
<hr />
<div>==IndirectPriorityQueue.cpp==<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
<br />
#include <boost/graph/grid_graph.hpp><br />
#include <boost/graph/detail/d_ary_heap.hpp><br />
#include <boost/property_map/property_map.hpp><br />
<br />
#include <cstdlib><br />
<br />
int main(int, char*[])<br />
{<br />
srand((unsigned int)time(NULL));<br />
<br />
boost::array<std::size_t, 2> lengths = { { 5,5 } };<br />
typedef boost::grid_graph<2> GraphType;<br />
GraphType graph(lengths);<br />
typedef boost::graph_traits<GraphType>::vertex_descriptor Vertex;<br />
typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type GridIndexMapType;<br />
GridIndexMapType gridIndexMap(get(boost::vertex_index, graph));<br />
<br />
typedef boost::vector_property_map<std::size_t, GridIndexMapType> IndexInHeapMap;<br />
IndexInHeapMap index_in_heap(gridIndexMap);<br />
<br />
typedef boost::graph_traits<GraphType>::vertex_iterator VertexIteratorType;<br />
<br />
typedef boost::vector_property_map<float, GridIndexMapType> PriorityMapType;<br />
PriorityMapType priorityMap(gridIndexMap);<br />
VertexIteratorType vertexIterator, vertexIteratorEnd;<br />
<br />
typedef std::greater<float> ComparisonFunctor;<br />
typedef boost::d_ary_heap_indirect<Vertex, 4, IndexInHeapMap, PriorityMapType, ComparisonFunctor > MutableQueue;<br />
<br />
ComparisonFunctor comparisonFunctor;<br />
MutableQueue mutableQueue(priorityMap, index_in_heap, comparisonFunctor);<br />
<br />
std::cout << "There are " << mutableQueue.size() << " items in the queue." << std::endl;<br />
<br />
// Add random values to the vertices and add them to the queue<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
put(priorityMap, *vertexIterator, rand() % 1000);<br />
}<br />
<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
mutableQueue.push(*vertexIterator);<br />
}<br />
<br />
std::cout << "There are " << mutableQueue.size() << " items in the queue." << std::endl;<br />
<br />
// Insert another set of random values for each vertex<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
put(priorityMap, *vertexIterator, rand() % 1000);<br />
}<br />
<br />
for( tie(vertexIterator, vertexIteratorEnd) = vertices(graph); vertexIterator != vertexIteratorEnd; ++vertexIterator)<br />
{<br />
mutableQueue.push(*vertexIterator);<br />
}<br />
<br />
std::cout << "There are " << mutableQueue.size() << " items in the queue." << std::endl;<br />
<br />
std::cout << "The priority queue is: " << std::endl;<br />
while( ! mutableQueue.empty() )<br />
{<br />
Vertex u = mutableQueue.top();<br />
<br />
// These two lines are equivalent<br />
std::cout << "vertex: " << u[0] << " " << u[1] << " priority: " << get(priorityMap, u) << std::endl;<br />
<br />
mutableQueue.pop();<br />
}<br />
<br />
std::cout << std::endl;<br />
<br />
return 0;<br />
}<br />
<br />
/* Output:<br />
There are 0 items in the queue.<br />
There are 25 items in the queue.<br />
There are 50 items in the queue.<br />
The priority queue is: <br />
vertex: 2 4 priority: 967<br />
vertex: 0 0 priority: 945<br />
vertex: 0 0 priority: 945<br />
vertex: 1 3 priority: 922<br />
vertex: 0 2 priority: 907<br />
vertex: 4 4 priority: 901<br />
vertex: 2 4 priority: 967<br />
vertex: 4 4 priority: 901<br />
vertex: 0 1 priority: 858<br />
vertex: 0 2 priority: 907<br />
vertex: 0 1 priority: 858<br />
vertex: 3 4 priority: 852<br />
vertex: 3 4 priority: 852<br />
vertex: 2 2 priority: 793<br />
vertex: 2 2 priority: 793<br />
vertex: 1 3 priority: 922<br />
vertex: 1 1 priority: 791<br />
vertex: 1 1 priority: 791<br />
vertex: 4 2 priority: 781<br />
vertex: 4 2 priority: 781<br />
vertex: 1 2 priority: 748<br />
vertex: 1 2 priority: 748<br />
vertex: 2 3 priority: 734<br />
vertex: 4 3 priority: 661<br />
vertex: 4 3 priority: 661<br />
vertex: 2 3 priority: 734<br />
vertex: 3 3 priority: 652<br />
vertex: 3 3 priority: 652<br />
vertex: 3 2 priority: 529<br />
vertex: 3 2 priority: 529<br />
vertex: 3 0 priority: 493<br />
vertex: 3 0 priority: 493<br />
vertex: 2 0 priority: 488<br />
vertex: 2 0 priority: 488<br />
vertex: 4 1 priority: 450<br />
vertex: 4 1 priority: 450<br />
vertex: 4 0 priority: 346<br />
vertex: 4 0 priority: 346<br />
vertex: 0 3 priority: 328<br />
vertex: 0 3 priority: 328<br />
vertex: 1 4 priority: 245<br />
vertex: 1 4 priority: 245<br />
vertex: 1 0 priority: 216<br />
vertex: 1 0 priority: 216<br />
vertex: 0 4 priority: 64<br />
vertex: 0 4 priority: 64<br />
vertex: 2 1 priority: 47<br />
vertex: 2 1 priority: 47<br />
vertex: 3 1 priority: 14<br />
vertex: 3 1 priority: 14<br />
<br />
*/<br />
</source><br />
<br />
==CMakeLists.txt==<br />
<source lang="cmake"><br />
cmake_minimum_required(VERSION 2.6)<br />
<br />
Project(IndirectPriorityQueue)<br />
<br />
set(Boost_USE_MULTITHREADED ON)<br />
FIND_PACKAGE(Boost 1.38 COMPONENTS)<br />
<br />
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})<br />
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})<br />
<br />
ADD_EXECUTABLE(IndirectPriorityQueue IndirectPriorityQueue.cpp)<br />
<br />
</source></div>
Daviddoria